Module: Foobara::Domain::DomainModuleExtension::ClassMethods
- Defined in:
- foobara-0.5.8/projects/command/src/extensions/domain/domain_module_extension.rb,
foobara-0.5.8/projects/typesystem/projects/domain/src/domain_module_extension.rb,
foobara-0.5.8/projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb
Instance Attribute Summary collapse
-
#foobara_default_entity_base ⇒ Object
readonly
Returns the value of attribute foobara_default_entity_base.
- #foobara_domain_name ⇒ Object
- #foobara_full_domain_name ⇒ Object
Instance Method Summary collapse
- #foobara_can_call_subcommands_from?(other_domain) ⇒ Boolean
- #foobara_command_classes ⇒ Object
- #foobara_depends_on(*domains) ⇒ Object
- #foobara_depends_on?(other_domain) ⇒ Boolean
- #foobara_domain? ⇒ Boolean
- #foobara_domain_map(*args, to: nil, strict: false, criteria: nil, should_raise: false, **opts) ⇒ Object
- #foobara_domain_map! ⇒ Object
- #foobara_full_domain_symbol ⇒ Object
- #foobara_full_organization_name ⇒ Object
- #foobara_manifest ⇒ Object
- #foobara_organization ⇒ Object
- #foobara_organization_name ⇒ Object
- #foobara_register_and_deanonymize_entities(entity_names_to_attributes) ⇒ Object
- #foobara_register_and_deanonymize_entity(name) ⇒ Object
- #foobara_register_entities(entity_names_to_attributes) ⇒ Object
-
#foobara_register_entity(name, *args, &block) ⇒ Object
TODO: kill this off.
- #foobara_register_type(type_symbol, *type_declaration_bits, &block) ⇒ Object
- #foobara_set_entity_base(name: nil, table_prefix: nil) ⇒ Object
-
#foobara_type_builder ⇒ Object
TODO: kill this off.
- #foobara_type_from_declaration(*args, **opts, &block) ⇒ Object
- #foobara_type_from_strict_declaration ⇒ Object
- #foobara_type_from_strict_stringified_declaration ⇒ Object
Instance Attribute Details
#foobara_default_entity_base ⇒ Object (readonly)
Returns the value of attribute foobara_default_entity_base.
5 6 7 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 5 def @foobara_default_entity_base end |
#foobara_domain_name ⇒ Object
66 67 68 69 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 66 def # TODO: does this work properly with prefixes? @foobara_domain_name || scoped_name end |
#foobara_full_domain_name ⇒ Object
71 72 73 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 71 def @foobara_full_domain_name || scoped_full_name end |
Instance Method Details
#foobara_can_call_subcommands_from?(other_domain) ⇒ Boolean
9 10 11 12 |
# File 'projects/command/src/extensions/domain/domain_module_extension.rb', line 9 def (other_domain) other_domain = Domain.to_domain(other_domain) other_domain == self || self == GlobalDomain || (other_domain) end |
#foobara_command_classes ⇒ Object
5 6 7 |
# File 'projects/command/src/extensions/domain/domain_module_extension.rb', line 5 def (mode: Namespace::LookupMode::DIRECT) end |
#foobara_depends_on(*domains) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 198 def (*domains) if domains.empty? return @foobara_depends_on ||= Set.new end if domains.length == 1 domains = Util.array(domains.first) end domains.each do |domain| # It very likely could be a module extended with domain methods... domain = Domain.to_domain(domain) domain_name = domain. if .include?(domain_name) # :nocov: raise AlreadyRegisteredDomainDependency, "Already registered #{domain_name} as a dependency of #{self}" # :nocov: end << domain .accesses << domain. lru_cache.reset! << domain_name end end |
#foobara_depends_on?(other_domain) ⇒ Boolean
193 194 195 196 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 193 def (other_domain) other_domain = Domain.to_domain(other_domain) other_domain == GlobalDomain || .include?(other_domain.) end |
#foobara_domain? ⇒ Boolean
100 101 102 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 100 def true end |
#foobara_domain_map(*args, to: nil, strict: false, criteria: nil, should_raise: false, **opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 20 def (*args, to: nil, strict: false, criteria: nil, should_raise: false, **opts) case args.size when 1 value = args.first when 0 if opts.empty? # :nocov: raise ArgumentError, "Expected at least one argument" # :nocov: else value = opts opts = {} end else # :nocov: raise ArgumentError, "Expected 1 argument but got #{args.size}" # :nocov: end invalid_keys = opts.keys - [:from] if invalid_keys.any? # :nocov: raise ArgumentError, "Invalid options: #{invalid_keys.join(", ")}" # :nocov: end from = if opts.key?(:from) opts[:from] else value end mapper = lookup_matching_domain_mapper(from:, to:, criteria:, strict:) if mapper mapper.map!(value) elsif should_raise raise Foobara::DomainMapperLookups::NoDomainMapperFoundError.new(from, to, value:) end end |
#foobara_domain_map! ⇒ Object
62 63 64 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 62 def (*, **, &) (*, should_raise: true, **, &) end |
#foobara_full_domain_symbol ⇒ Object
75 76 77 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 75 def Util.underscore_sym() end |
#foobara_full_organization_name ⇒ Object
83 84 85 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 83 def &. end |
#foobara_manifest ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 226 def to_include = TypeDeclarations. depends_on = .map do |name| domain = Domain.to_domain(name) if to_include to_include << domain end domain. end.sort types = (mode: Namespace::LookupMode::DIRECT).map do |type| if to_include to_include << type end type. end.sort manifest = super.merge(types:) unless depends_on.empty? manifest[:depends_on] = depends_on end manifest end |
#foobara_organization ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 87 def parent = while parent return parent if parent&. # TODO: we really should test this path # :nocov: parent = parent. # :nocov: end || GlobalOrganization end |
#foobara_organization_name ⇒ Object
79 80 81 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 79 def &. end |
#foobara_register_and_deanonymize_entities(entity_names_to_attributes) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 89 def (entity_names_to_attributes) entities = [] entity_names_to_attributes.each_pair do |entity_name, attributes_declaration| entities << (entity_name, attributes_declaration) end entities end |
#foobara_register_and_deanonymize_entity(name) ⇒ Object
13 14 15 16 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 13 def (name, *, &) entity_class = (name, *, &) Foobara::Model.deanonymize_class(entity_class) end |
#foobara_register_entities(entity_names_to_attributes) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 99 def (entity_names_to_attributes) entities = [] entity_names_to_attributes.each_pair do |entity_name, attributes_type_declaration| entities << (entity_name, attributes_type_declaration) end entities end |
#foobara_register_entity(name, *args, &block) ⇒ Object
TODO: kill this off
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 19 def (name, *args, &block) # TODO: introduce a Namespace#scope method to simplify this a bit Foobara::Namespace.use self do if block args = [ TypeDeclarations::Dsl::Attributes.to_declaration(&block).declaration_data, *args ] end attributes_type_declaration, *args = args model_base_class, description = case args.size when 0 [] when 1, 2 arg, other = args if args.first.is_a?(::String) [other, arg] else args end else # :nocov: raise ArgumentError, "Too many arguments" # :nocov: end if model_base_class attributes_type_declaration = TypeDeclarations::Attributes.merge( model_base_class.attributes_type.declaration_data, attributes_type_declaration ) end handler = .handler_for_class( Foobara::TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration ) attributes_type = handler.type_for_declaration(attributes_type_declaration) # TODO: reuse the model_base_class primary key if it has one... primary_key = attributes_type.element_types.keys.first model_module = unless scoped_full_path.empty? scoped_full_name end declaration = TypeDeclaration.new( Util.remove_blank( type: :entity, name:, model_base_class:, model_module:, attributes_declaration: attributes_type_declaration, primary_key:, description: ) ) declaration.is_absolutified = true declaration.is_duped = true entity_type = .type_for_declaration(declaration) entity_type.target_class end end |
#foobara_register_type(type_symbol, *type_declaration_bits, &block) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 134 def (type_symbol, *type_declaration_bits, &block) type = if block.nil? && type_declaration_bits.size == 1 && type_declaration_bits.first.is_a?(Types::Type) type_declaration_bits.first else (*type_declaration_bits, &block) end new_scoped_path, new_type_symbol = if type_symbol.is_a?(::Array) [type_symbol, type_symbol.join("::").to_sym] else type_symbol = type_symbol.to_s if type_symbol.is_a?(::Symbol) [type_symbol.split("::"), type_symbol.to_sym] end if type.scoped_path_set? && type.registered? && (type, mode: Namespace::LookupMode::DIRECT) old_symbol = type.type_symbol old_type = (old_symbol, mode: Namespace::LookupMode::DIRECT) if old_symbol != new_type_symbol (type) type.scoped_path = new_scoped_path type.type_symbol = new_type_symbol (type) # :nocov: elsif old_type != type # TODO: delete this check if it's not really helping raise "Didn't expect to find an old type" # :nocov: end else type.scoped_path = new_scoped_path type.type_symbol = new_type_symbol old_type = (new_type_symbol, mode: Namespace::LookupMode::DIRECT) if old_type && old_type != type # TODO: delete this check if it's not really helping # :nocov: raise "Didn't expect to find an old type" # :nocov: end if (type, mode: Namespace::LookupMode::DIRECT) # TODO: delete this check if it's not really helping # :nocov: raise "Already registered: #{type.inspect}" # :nocov: end (type) end type end |
#foobara_set_entity_base(name: nil, table_prefix: nil) ⇒ Object
7 8 9 10 11 |
# File 'projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb', line 7 def (*, name: nil, table_prefix: nil) name ||= Util.underscore(scoped_full_name).gsub("::", "_") base = Persistence.register_base(*, name:, table_prefix:) @foobara_default_entity_base = base end |
#foobara_type_builder ⇒ Object
TODO: kill this off
105 106 107 108 109 110 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 105 def @foobara_type_builder ||= begin accesses = self == GlobalDomain ? [] : GlobalDomain. TypeDeclarations::TypeBuilder.new(, accesses:) end end |
#foobara_type_from_declaration(*args, **opts, &block) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'projects/typesystem/projects/domain/src/domain_module_extension.rb', line 112 def (*args, **opts, &block) if opts.empty? && block.nil? && args.size == 1 && args.first.is_a?(Types::Type) return args.first end Foobara::Namespace.use self do .type_for_declaration(*args, **opts, &block) end end |