foobara 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +5 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +10 -0
- data/DECISION_LOG.md +220 -0
- data/Guardfile +9 -0
- data/LICENSE-AGPL.txt +666 -0
- data/LICENSE.txt +4 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/concepts.md +153 -0
- data/projects/builtin_types/lib/foobara/builtin_types.rb +67 -0
- data/projects/builtin_types/src/README.md +140 -0
- data/projects/builtin_types/src/array/casters/arrayable.rb +22 -0
- data/projects/builtin_types/src/array/supported_processors/element_type_declaration.rb +41 -0
- data/projects/builtin_types/src/array/supported_validators/size.rb +43 -0
- data/projects/builtin_types/src/associative_array/casters/array.rb +22 -0
- data/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb +44 -0
- data/projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb +44 -0
- data/projects/builtin_types/src/atomic_duck.rb +6 -0
- data/projects/builtin_types/src/attributes/casters/array.rb +33 -0
- data/projects/builtin_types/src/attributes/casters/hash.rb +28 -0
- data/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb +89 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_defaults_from_element_types_to_root.rb +40 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/symbolize_defaults.rb +31 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/hash_with_symbolic_keys.rb +37 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/valid_attribute_names.rb +60 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults.rb +41 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_required_from_element_types_to_root.rb +55 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_of_symbols.rb +47 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb +54 -0
- data/projects/builtin_types/src/attributes/supported_validators/required.rb +51 -0
- data/projects/builtin_types/src/big_decimal/casters/integer.rb +21 -0
- data/projects/builtin_types/src/big_decimal/casters/string.rb +24 -0
- data/projects/builtin_types/src/boolean/casters/numeric.rb +21 -0
- data/projects/builtin_types/src/boolean/casters/string_or_symbol.rb +27 -0
- data/projects/builtin_types/src/builtin_types.rb +189 -0
- data/projects/builtin_types/src/date/casters/hash.rb +23 -0
- data/projects/builtin_types/src/date/casters/string.rb +40 -0
- data/projects/builtin_types/src/datetime/casters/date.rb +21 -0
- data/projects/builtin_types/src/datetime/casters/hash.rb +77 -0
- data/projects/builtin_types/src/datetime/casters/seconds_since_epoch.rb +21 -0
- data/projects/builtin_types/src/datetime/casters/string.rb +31 -0
- data/projects/builtin_types/src/duck/supported_casters/allow_nil.rb +38 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_desugarizer.rb +29 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_class_desugarizer.rb +31 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_symbol_desugarizer.rb +31 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb +43 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of.rb +42 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb +37 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb +41 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of.rb +41 -0
- data/projects/builtin_types/src/duck.rb +6 -0
- data/projects/builtin_types/src/duckture.rb +6 -0
- data/projects/builtin_types/src/email/transformers/downcase.rb +15 -0
- data/projects/builtin_types/src/email/validator_base.rb +94 -0
- data/projects/builtin_types/src/float/casters/integer.rb +21 -0
- data/projects/builtin_types/src/float/casters/string.rb +24 -0
- data/projects/builtin_types/src/integer/casters/string.rb +23 -0
- data/projects/builtin_types/src/number/supported_validators/max.rb +41 -0
- data/projects/builtin_types/src/number/supported_validators/min.rb +41 -0
- data/projects/builtin_types/src/string/casters/numeric.rb +21 -0
- data/projects/builtin_types/src/string/casters/symbol.rb +21 -0
- data/projects/builtin_types/src/string/supported_transformers/downcase.rb +11 -0
- data/projects/builtin_types/src/string/supported_validators/matches.rb +41 -0
- data/projects/builtin_types/src/string/supported_validators/max_length.rb +37 -0
- data/projects/builtin_types/src/symbol/casters/string.rb +21 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb +32 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb +50 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb +59 -0
- data/projects/callback/lib/foobara/callback.rb +1 -0
- data/projects/callback/src/block/after.rb +10 -0
- data/projects/callback/src/block/around.rb +10 -0
- data/projects/callback/src/block/before.rb +10 -0
- data/projects/callback/src/block/concerns/block_parameter_not_allowed.rb +21 -0
- data/projects/callback/src/block/concerns/block_parameter_required.rb +21 -0
- data/projects/callback/src/block/concerns/keyword_argumentable_block.rb +31 -0
- data/projects/callback/src/block/concerns/single_argument_block.rb +22 -0
- data/projects/callback/src/block/concerns/type.rb +17 -0
- data/projects/callback/src/block/error.rb +10 -0
- data/projects/callback/src/block.rb +83 -0
- data/projects/callback/src/registry/base.rb +90 -0
- data/projects/callback/src/registry/chained_conditioned.rb +24 -0
- data/projects/callback/src/registry/chained_multiple_action.rb +24 -0
- data/projects/callback/src/registry/conditioned.rb +101 -0
- data/projects/callback/src/registry/multiple_action.rb +110 -0
- data/projects/callback/src/registry/single_action.rb +15 -0
- data/projects/callback/src/runner.rb +89 -0
- data/projects/callback/src/set.rb +56 -0
- data/projects/command/lib/foobara/command.rb +9 -0
- data/projects/command/src/command/entity_helpers.rb +145 -0
- data/projects/command/src/command.rb +36 -0
- data/projects/command/src/concerns/callbacks.rb +93 -0
- data/projects/command/src/concerns/description.rb +23 -0
- data/projects/command/src/concerns/domain_mappers.rb +35 -0
- data/projects/command/src/concerns/entities.rb +88 -0
- data/projects/command/src/concerns/errors.rb +181 -0
- data/projects/command/src/concerns/errors_type.rb +124 -0
- data/projects/command/src/concerns/inputs.rb +59 -0
- data/projects/command/src/concerns/inputs_type.rb +58 -0
- data/projects/command/src/concerns/namespace.rb +49 -0
- data/projects/command/src/concerns/reflection.rb +137 -0
- data/projects/command/src/concerns/result.rb +25 -0
- data/projects/command/src/concerns/result_type.rb +29 -0
- data/projects/command/src/concerns/runtime.rb +119 -0
- data/projects/command/src/concerns/state_machine.rb +12 -0
- data/projects/command/src/concerns/subcommands.rb +102 -0
- data/projects/command/src/concerns/transactions.rb +81 -0
- data/projects/command/src/state_machine.rb +57 -0
- data/projects/command/src/transformed_command.rb +459 -0
- data/projects/command_connectors/lib/foobara/command_connectors.rb +12 -0
- data/projects/command_connectors/src/command_connector.rb +401 -0
- data/projects/command_connectors/src/command_registry/allowed_rule.rb +29 -0
- data/projects/command_connectors/src/command_registry/exposed_command.rb +140 -0
- data/projects/command_connectors/src/command_registry/exposed_domain.rb +30 -0
- data/projects/command_connectors/src/command_registry/exposed_organization.rb +30 -0
- data/projects/command_connectors/src/command_registry.rb +257 -0
- data/projects/command_connectors/src/commands/describe.rb +36 -0
- data/projects/command_connectors/src/commands/list_commands.rb +51 -0
- data/projects/command_connectors/src/commands/ping.rb +21 -0
- data/projects/command_connectors/src/commands/query_git_commit_info.rb +81 -0
- data/projects/command_connectors/src/request.rb +99 -0
- data/projects/command_connectors/src/response.rb +17 -0
- data/projects/command_connectors/src/serializer.rb +25 -0
- data/projects/command_connectors/src/serializers/aggregate_serializer.rb +32 -0
- data/projects/command_connectors/src/serializers/atomic_serializer.rb +25 -0
- data/projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb +28 -0
- data/projects/command_connectors/src/serializers/errors_serializer.rb +18 -0
- data/projects/command_connectors/src/serializers/json_serializer.rb +20 -0
- data/projects/command_connectors/src/serializers/noop_serializer.rb +20 -0
- data/projects/command_connectors/src/serializers/record_store_serializer.rb +31 -0
- data/projects/command_connectors/src/serializers/success_serializer.rb +14 -0
- data/projects/command_connectors/src/serializers/yaml_serializer.rb +20 -0
- data/projects/command_connectors/src/transformers/auth_errors_transformer.rb +35 -0
- data/projects/command_connectors/src/transformers/load_aggregates_pre_commit_transformer.rb +36 -0
- data/projects/command_connectors_http/lib/foobara/command_connectors_http.rb +6 -0
- data/projects/command_connectors_http/src/http/commands/get_options.rb +16 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/command.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/domain.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/entity.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/error.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/model.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/organization.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor_class.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/root.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/type.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter.rb +162 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/command.html.erb +11 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/domain.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/entity.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/error.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/model.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/organization.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/processor.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/processor_class.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/root.html.erb +3 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/type.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help.rb +98 -0
- data/projects/command_connectors_http/src/http/request.rb +98 -0
- data/projects/command_connectors_http/src/http/response.rb +14 -0
- data/projects/command_connectors_http/src/http.rb +84 -0
- data/projects/common/lib/foobara/common.rb +11 -0
- data/projects/common/src/data_path.rb +272 -0
- data/projects/common/src/error.rb +215 -0
- data/projects/common/src/error_collection.rb +97 -0
- data/projects/common/src/error_key.rb +168 -0
- data/projects/common/src/outcome.rb +101 -0
- data/projects/common/src/possible_error.rb +80 -0
- data/projects/common/src/runtime_error.rb +24 -0
- data/projects/concerns/lib/foobara/concerns.rb +1 -0
- data/projects/concerns/src/concern.rb +93 -0
- data/projects/delegate/lib/foobara/delegate.rb +1 -0
- data/projects/delegate/src/extensions/module.rb +12 -0
- data/projects/domain/lib/foobara/domain.rb +25 -0
- data/projects/domain/src/domain.rb +65 -0
- data/projects/domain/src/domain_mapper/registry.rb +47 -0
- data/projects/domain/src/domain_mapper.rb +162 -0
- data/projects/domain/src/domain_module_extension.rb +510 -0
- data/projects/domain/src/extensions/foobara.rb +69 -0
- data/projects/domain/src/global_domain.rb +14 -0
- data/projects/domain/src/global_organization.rb +12 -0
- data/projects/domain/src/is_manifestable.rb +68 -0
- data/projects/domain/src/manifestable.rb +12 -0
- data/projects/domain/src/module_extension.rb +122 -0
- data/projects/domain/src/organization.rb +52 -0
- data/projects/domain/src/organization_module_extension.rb +50 -0
- data/projects/entity/lib/foobara/entity.rb +27 -0
- data/projects/entity/src/concerns/associations.rb +241 -0
- data/projects/entity/src/concerns/attributes.rb +170 -0
- data/projects/entity/src/concerns/callbacks.rb +97 -0
- data/projects/entity/src/concerns/initialization.rb +127 -0
- data/projects/entity/src/concerns/persistence.rb +142 -0
- data/projects/entity/src/concerns/primary_key.rb +43 -0
- data/projects/entity/src/concerns/queries.rb +96 -0
- data/projects/entity/src/concerns/reflection.rb +51 -0
- data/projects/entity/src/concerns/transactions.rb +31 -0
- data/projects/entity/src/concerns/types.rb +31 -0
- data/projects/entity/src/entity.rb +61 -0
- data/projects/entity/src/extensions/builtin_types/entity/casters/hash.rb +33 -0
- data/projects/entity/src/extensions/builtin_types/entity/validators/attributes_declaration.rb +32 -0
- data/projects/entity/src/extensions/builtin_types/entity.rb +6 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/attributes_handler_desugarizer.rb +14 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/hash_desugarizer.rb +43 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/model_class_desugarizer.rb +21 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/primary_key_desugarizer.rb +19 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb +64 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_is_symbol.rb +35 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_present.rb +27 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_references_attribute.rb +36 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration.rb +11 -0
- data/projects/entity/src/new_prepend.rb +21 -0
- data/projects/entity/src/not_found_error.rb +72 -0
- data/projects/enumerated/lib/foobara/enumerated.rb +1 -0
- data/projects/enumerated/src/accessors.rb +61 -0
- data/projects/enumerated/src/values.rb +121 -0
- data/projects/foobara/lib/foobara/all.rb +44 -0
- data/projects/in_memory_crud_driver/lib/foobara/in_memory_crud_driver.rb +3 -0
- data/projects/in_memory_crud_driver/src/in_memory.rb +10 -0
- data/projects/in_memory_crud_driver_minimal/lib/foobara/in_memory_crud_driver_minimal.rb +1 -0
- data/projects/in_memory_crud_driver_minimal/src/in_memory_minimal.rb +113 -0
- data/projects/manifest/lib/foobara/manifest.rb +4 -0
- data/projects/manifest/src/foobara/manifest/array.rb +13 -0
- data/projects/manifest/src/foobara/manifest/attributes.rb +40 -0
- data/projects/manifest/src/foobara/manifest/base_manifest.rb +161 -0
- data/projects/manifest/src/foobara/manifest/command.rb +59 -0
- data/projects/manifest/src/foobara/manifest/domain.rb +43 -0
- data/projects/manifest/src/foobara/manifest/entity.rb +35 -0
- data/projects/manifest/src/foobara/manifest/error.rb +33 -0
- data/projects/manifest/src/foobara/manifest/model.rb +43 -0
- data/projects/manifest/src/foobara/manifest/organization.rb +45 -0
- data/projects/manifest/src/foobara/manifest/possible_error.rb +30 -0
- data/projects/manifest/src/foobara/manifest/processor.rb +11 -0
- data/projects/manifest/src/foobara/manifest/processor_class.rb +11 -0
- data/projects/manifest/src/foobara/manifest/root_manifest.rb +112 -0
- data/projects/manifest/src/foobara/manifest/type.rb +86 -0
- data/projects/manifest/src/foobara/manifest/type_declaration.rb +117 -0
- data/projects/model/lib/foobara/model.rb +23 -0
- data/projects/model/src/concerns/reflection.rb +22 -0
- data/projects/model/src/concerns/types.rb +104 -0
- data/projects/model/src/extensions/builtin_types/model/casters/hash.rb +23 -0
- data/projects/model/src/extensions/builtin_types/model/transformers/mutable.rb +26 -0
- data/projects/model/src/extensions/builtin_types/model/validators/attributes_declaration.rb +33 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +24 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +32 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +119 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +57 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +21 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +37 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +25 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +46 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +28 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +27 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +31 -0
- data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -0
- data/projects/model/src/model.rb +320 -0
- data/projects/monorepo/lib/foobara/monorepo/project.rb +52 -0
- data/projects/monorepo/lib/foobara/monorepo.rb +63 -0
- data/projects/namespace/lib/foobara/namespace.rb +4 -0
- data/projects/namespace/src/ambiguous_registry.rb +104 -0
- data/projects/namespace/src/base_registry.rb +66 -0
- data/projects/namespace/src/extensions/module.rb +5 -0
- data/projects/namespace/src/is_namespace.rb +352 -0
- data/projects/namespace/src/namespace/lookup_mode.rb +41 -0
- data/projects/namespace/src/namespace.rb +61 -0
- data/projects/namespace/src/namespace_helpers.rb +273 -0
- data/projects/namespace/src/prefixless_registry.rb +54 -0
- data/projects/namespace/src/scoped.rb +113 -0
- data/projects/namespace/src/unambiguous_registry.rb +65 -0
- data/projects/persistence/lib/foobara/persistence.rb +22 -0
- data/projects/persistence/src/entity_attributes_crud_driver.rb +241 -0
- data/projects/persistence/src/entity_base/table.rb +14 -0
- data/projects/persistence/src/entity_base/transaction/concerns/entity_callback_handling.rb +157 -0
- data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +83 -0
- data/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb +53 -0
- data/projects/persistence/src/entity_base/transaction/state_machine.rb +27 -0
- data/projects/persistence/src/entity_base/transaction.rb +163 -0
- data/projects/persistence/src/entity_base/transaction_table/concerns/queries.rb +42 -0
- data/projects/persistence/src/entity_base/transaction_table/concerns/record_tracking.rb +134 -0
- data/projects/persistence/src/entity_base/transaction_table.rb +620 -0
- data/projects/persistence/src/entity_base.rb +114 -0
- data/projects/persistence/src/persistence.rb +172 -0
- data/projects/state_machine/lib/foobara/state_machine.rb +1 -0
- data/projects/state_machine/src/callbacks.rb +158 -0
- data/projects/state_machine/src/log_entry.rb +13 -0
- data/projects/state_machine/src/state_machine.rb +91 -0
- data/projects/state_machine/src/sugar.rb +125 -0
- data/projects/state_machine/src/transition_log.rb +19 -0
- data/projects/state_machine/src/validations.rb +69 -0
- data/projects/thread_parent/lib/foobara/thread_parent.rb +1 -0
- data/projects/thread_parent/src/thread_parent.rb +38 -0
- data/projects/type_declarations/lib/foobara/type_declarations.rb +131 -0
- data/projects/type_declarations/src/attributes.rb +34 -0
- data/projects/type_declarations/src/caster.rb +7 -0
- data/projects/type_declarations/src/desugarizer.rb +25 -0
- data/projects/type_declarations/src/dsl/attributes.rb +199 -0
- data/projects/type_declarations/src/element_processor.rb +7 -0
- data/projects/type_declarations/src/error_extension.rb +73 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +31 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +37 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +22 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +36 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +14 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +28 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +20 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +25 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +34 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +60 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +21 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +16 -0
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +75 -0
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +23 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +30 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +24 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +13 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +29 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +65 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +32 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +39 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +26 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +28 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +24 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration.rb +26 -0
- data/projects/type_declarations/src/processor.rb +7 -0
- data/projects/type_declarations/src/to_type_transformer.rb +11 -0
- data/projects/type_declarations/src/transformer.rb +7 -0
- data/projects/type_declarations/src/type_builder.rb +112 -0
- data/projects/type_declarations/src/type_declaration_error.rb +9 -0
- data/projects/type_declarations/src/type_declaration_handler.rb +120 -0
- data/projects/type_declarations/src/type_declaration_handler_registry.rb +27 -0
- data/projects/type_declarations/src/type_declaration_validator.rb +19 -0
- data/projects/type_declarations/src/type_declarations.rb +128 -0
- data/projects/type_declarations/src/typed_transformer.rb +89 -0
- data/projects/type_declarations/src/validator.rb +7 -0
- data/projects/type_declarations/src/with_registries.rb +41 -0
- data/projects/types/lib/foobara/types.rb +11 -0
- data/projects/types/src/element_processor.rb +7 -0
- data/projects/types/src/extensions/error.rb +32 -0
- data/projects/types/src/type/concerns/reflection.rb +79 -0
- data/projects/types/src/type/concerns/supported_processor_registration.rb +56 -0
- data/projects/types/src/type.rb +375 -0
- data/projects/types/src/types.rb +4 -0
- data/projects/value/lib/foobara/value.rb +7 -0
- data/projects/value/src/caster.rb +84 -0
- data/projects/value/src/data_error.rb +27 -0
- data/projects/value/src/processor/casting.rb +123 -0
- data/projects/value/src/processor/multi.rb +63 -0
- data/projects/value/src/processor/pipeline.rb +27 -0
- data/projects/value/src/processor/runner.rb +38 -0
- data/projects/value/src/processor/selection.rb +90 -0
- data/projects/value/src/processor.rb +358 -0
- data/projects/value/src/transformer.rb +84 -0
- data/projects/value/src/validator.rb +53 -0
- data/projects/version/lib/foobara/version.rb +4 -0
- data/projects/version/src/version.rb +5 -0
- data/projects/weak_object_set/lib/foobara/weak_object_set.rb +3 -0
- data/projects/weak_object_set/src/weak_object_set.rb +163 -0
- metadata +445 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module Foobara
|
2
|
+
class DomainMapper
|
3
|
+
class Registry
|
4
|
+
class AmbiguousDomainMapperError < StandardError
|
5
|
+
attr_accessor :candidates, :from, :to
|
6
|
+
|
7
|
+
def initialize(from, to, candidates)
|
8
|
+
self.to = to
|
9
|
+
self.from = from
|
10
|
+
self.candidates = [*candidates].flatten
|
11
|
+
|
12
|
+
super("#{candidates.size} ambiguous candidates found.")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def register(mapper)
|
17
|
+
mappers << mapper
|
18
|
+
end
|
19
|
+
|
20
|
+
def lookup(from: nil, to: nil, strict: false)
|
21
|
+
candidates = mappers.select do |mapper|
|
22
|
+
mapper.applicable?(from, to)
|
23
|
+
end
|
24
|
+
|
25
|
+
if candidates.size > 1
|
26
|
+
raise AmbiguousDomainMapperError.new(from, to, candidates)
|
27
|
+
end
|
28
|
+
|
29
|
+
value = candidates.first
|
30
|
+
|
31
|
+
return value if value
|
32
|
+
|
33
|
+
unless strict
|
34
|
+
if from
|
35
|
+
lookup(from: nil, to:)
|
36
|
+
elsif to
|
37
|
+
lookup(from:, to: nil)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def mappers
|
43
|
+
@mappers ||= []
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Foobara
|
2
|
+
class DomainMapper
|
3
|
+
class << self
|
4
|
+
def call(value)
|
5
|
+
instance.call(value)
|
6
|
+
end
|
7
|
+
|
8
|
+
def from(*args)
|
9
|
+
if args.empty?
|
10
|
+
@from
|
11
|
+
else
|
12
|
+
if args.size > 1
|
13
|
+
# :nocov:
|
14
|
+
raise ArgumentError, "only one argument allowed"
|
15
|
+
# :nocov:
|
16
|
+
end
|
17
|
+
|
18
|
+
@from = args.first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to(*args)
|
23
|
+
if args.empty?
|
24
|
+
@to
|
25
|
+
else
|
26
|
+
if args.size > 1
|
27
|
+
# :nocov:
|
28
|
+
raise ArgumentError, "only one argument allowed"
|
29
|
+
# :nocov:
|
30
|
+
end
|
31
|
+
|
32
|
+
@to = args.first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_type
|
37
|
+
return @from_type if defined?(@from_type)
|
38
|
+
|
39
|
+
@from_type = object_to_type(from)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_type
|
43
|
+
return @to_type if defined?(@to_type)
|
44
|
+
|
45
|
+
@to_type = object_to_type(to)
|
46
|
+
end
|
47
|
+
|
48
|
+
def instance
|
49
|
+
@instance ||= new
|
50
|
+
end
|
51
|
+
|
52
|
+
def inherited(subclass)
|
53
|
+
foobara_domain_mapper_to_process(subclass.instance)
|
54
|
+
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
def foobara_domain_mapper_to_process(mapper)
|
59
|
+
foobara_domain_mappers_to_process << mapper
|
60
|
+
end
|
61
|
+
|
62
|
+
def foobara_domain_mappers_to_process
|
63
|
+
@foobara_domain_mappers_to_process ||= []
|
64
|
+
end
|
65
|
+
|
66
|
+
def foobara_process_domain_mappers
|
67
|
+
if defined?(@foobara_domain_mappers_to_process)
|
68
|
+
@foobara_domain_mappers_to_process.each do |mapper|
|
69
|
+
mapper.domain.foobara_domain_mapper(mapper)
|
70
|
+
end
|
71
|
+
remove_instance_variable(:@foobara_domain_mappers_to_process)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def domain
|
76
|
+
candidate = self
|
77
|
+
|
78
|
+
loop do
|
79
|
+
candidate = Util.module_for(candidate)
|
80
|
+
|
81
|
+
if candidate.nil?
|
82
|
+
# :nocov:
|
83
|
+
raise "Domain mapper must be scoped within a domain but #{self.class.name} is not in a domain"
|
84
|
+
# :nocov:
|
85
|
+
elsif candidate.foobara_domain?
|
86
|
+
return candidate
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def matches?(type_indicator, value)
|
92
|
+
return true if type_indicator.nil? || value.nil? || type_indicator == value
|
93
|
+
|
94
|
+
type = object_to_type(type_indicator)
|
95
|
+
|
96
|
+
return true if type.nil? || type == value
|
97
|
+
return true if type.applicable?(value) && type.process_value(value).success?
|
98
|
+
|
99
|
+
if value.is_a?(Types::Type)
|
100
|
+
if !value.registered? && !type.registered?
|
101
|
+
value.declaration_data == type.declaration_data
|
102
|
+
end
|
103
|
+
else
|
104
|
+
value_type = object_to_type(value)
|
105
|
+
|
106
|
+
if value_type
|
107
|
+
matches?(type, value_type)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def object_to_type(object)
|
113
|
+
if object
|
114
|
+
if object.is_a?(::Class)
|
115
|
+
if object < Foobara::Model
|
116
|
+
object.model_type
|
117
|
+
elsif object < Foobara::Command
|
118
|
+
object.inputs_type
|
119
|
+
else
|
120
|
+
domain.foobara_type_from_declaration(object)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
case object
|
124
|
+
when Types::Type
|
125
|
+
object
|
126
|
+
when ::Symbol
|
127
|
+
domain.foobara_lookup_type!(object)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def from_type
|
135
|
+
self.class.from_type
|
136
|
+
end
|
137
|
+
|
138
|
+
def to_type
|
139
|
+
self.class.to_type
|
140
|
+
end
|
141
|
+
|
142
|
+
def call(from_value)
|
143
|
+
mapped_value = map(from_value)
|
144
|
+
|
145
|
+
to_type.process_value!(mapped_value)
|
146
|
+
end
|
147
|
+
|
148
|
+
def map(_from_value)
|
149
|
+
# :nocov:
|
150
|
+
raise "subclass repsonsibility"
|
151
|
+
# :nocov:
|
152
|
+
end
|
153
|
+
|
154
|
+
def applicable?(from_value, to_value)
|
155
|
+
self.class.matches?(from_type, from_value) && self.class.matches?(to_type, to_value)
|
156
|
+
end
|
157
|
+
|
158
|
+
def domain
|
159
|
+
self.class.domain
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,510 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Domain
|
3
|
+
class NoSuchDomain < StandardError; end
|
4
|
+
class AlreadyRegisteredError < StandardError; end
|
5
|
+
class CannotSetTypeConstantError < StandardError; end
|
6
|
+
|
7
|
+
class NoDomainMapperFoundError < StandardError
|
8
|
+
attr_accessor :value, :from, :to
|
9
|
+
|
10
|
+
def initialize(value, from, to)
|
11
|
+
self.value = value
|
12
|
+
self.from = from
|
13
|
+
self.to = to
|
14
|
+
|
15
|
+
super("No domain mapper found for #{value}. from: #{from}. to: #{to}.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def global
|
21
|
+
GlobalDomain
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module DomainModuleExtension
|
26
|
+
class << self
|
27
|
+
def all
|
28
|
+
@all ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: rename this
|
32
|
+
def _copy_constants(old_mod, new_class)
|
33
|
+
old_mod.constants.each do |const_name|
|
34
|
+
value = old_mod.const_get(const_name)
|
35
|
+
if new_class.const_defined?(const_name)
|
36
|
+
# TODO: figure out how to test this path. Seems to occur when models are nested and loaded
|
37
|
+
# remotely in a certain order
|
38
|
+
# :nocov:
|
39
|
+
to_replace = new_class.const_get(const_name)
|
40
|
+
if to_replace != value
|
41
|
+
new_class.send(:remove_const, const_name)
|
42
|
+
new_class.const_set(const_name, value)
|
43
|
+
end
|
44
|
+
# :nocov:
|
45
|
+
else
|
46
|
+
new_class.const_set(const_name, value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
lower_case_constants = old_mod.instance_variable_get(:@foobara_lowercase_constants)
|
51
|
+
|
52
|
+
if lower_case_constants && !lower_case_constants.empty?
|
53
|
+
lower_case_constants&.each do |lower_case_constant|
|
54
|
+
new_class.singleton_class.define_method lower_case_constant do
|
55
|
+
old_mod.send(lower_case_constant)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
new_lowercase_constants = new_class.instance_variable_get(:@foobara_lowercase_constants) || []
|
60
|
+
new_lowercase_constants += lower_case_constants
|
61
|
+
|
62
|
+
new_class.instance_variable_set(:@foobara_lowercase_constants, new_lowercase_constants)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
include Concern
|
68
|
+
include Manifestable
|
69
|
+
|
70
|
+
on_include do
|
71
|
+
DomainModuleExtension.all << self
|
72
|
+
end
|
73
|
+
|
74
|
+
module ClassMethods
|
75
|
+
attr_writer :foobara_domain_name, :foobara_full_domain_name
|
76
|
+
|
77
|
+
def foobara_unregister(scoped)
|
78
|
+
if scoped.is_a?(Foobara::Types::Type)
|
79
|
+
parent_mod = nil
|
80
|
+
|
81
|
+
if const_defined?(:Types, false)
|
82
|
+
parent_path = ["Foobara::GlobalDomain"]
|
83
|
+
unless scoped.type_symbol.to_s.start_with?("Types::")
|
84
|
+
parent_path << "Types"
|
85
|
+
end
|
86
|
+
parent_path += scoped.type_symbol.to_s.split("::")[..-2]
|
87
|
+
|
88
|
+
parent_name = parent_path.join("::")
|
89
|
+
child_name = [*parent_path, scoped.type_symbol.to_s.split("::").last].join("::")
|
90
|
+
removed = false
|
91
|
+
|
92
|
+
if Object.const_defined?(parent_name)
|
93
|
+
parent_mod = Object.const_get(parent_name)
|
94
|
+
|
95
|
+
if scoped.scoped_short_name =~ /^[a-z]/
|
96
|
+
lower_case_constants = parent_mod.instance_variable_get(:@foobara_lowercase_constants)
|
97
|
+
|
98
|
+
if lower_case_constants&.include?(scoped.scoped_short_name)
|
99
|
+
parent_mod.singleton_class.undef_method scoped.scoped_short_name
|
100
|
+
lower_case_constants.delete(scoped.scoped_short_name)
|
101
|
+
end
|
102
|
+
|
103
|
+
removed = true
|
104
|
+
elsif parent_mod.const_defined?(scoped.scoped_short_name, false)
|
105
|
+
parent_mod.send(:remove_const, scoped.scoped_short_name)
|
106
|
+
removed = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
if removed
|
111
|
+
child_name = parent_name
|
112
|
+
|
113
|
+
while child_name
|
114
|
+
child = Object.const_get(child_name)
|
115
|
+
|
116
|
+
break if child.foobara_domain?
|
117
|
+
|
118
|
+
break if child.foobara_organization?
|
119
|
+
break if child.constants(false).any? do |constant|
|
120
|
+
value = child.const_get(constant)
|
121
|
+
|
122
|
+
# TODO: can we make this not coupled to model project??
|
123
|
+
value.is_a?(Types::Type) || (value.is_a?(::Class) && value < Foobara::Model)
|
124
|
+
end
|
125
|
+
|
126
|
+
lower_case_constants = child.instance_variable_get(:@foobara_lowercase_constants)
|
127
|
+
break if lower_case_constants && !lower_case_constants.empty?
|
128
|
+
|
129
|
+
parent_name = Util.parent_module_name_for(child_name)
|
130
|
+
break unless Object.const_defined?(parent_name)
|
131
|
+
|
132
|
+
parent = Object.const_get(parent_name)
|
133
|
+
|
134
|
+
child_sym = Util.non_full_name(child).to_sym
|
135
|
+
parent.send(:remove_const, child_sym)
|
136
|
+
|
137
|
+
child_name = parent_name
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
super
|
144
|
+
end
|
145
|
+
|
146
|
+
def foobara_domain_map(value, to: nil, strict: false, **opts)
|
147
|
+
invalid_keys = opts.keys - [:from]
|
148
|
+
|
149
|
+
if invalid_keys.any?
|
150
|
+
# :nocov:
|
151
|
+
raise ArgumentError, "Invalid options: #{invalid_keys.join(", ")}"
|
152
|
+
# :nocov:
|
153
|
+
end
|
154
|
+
|
155
|
+
from = if opts.key?(:from)
|
156
|
+
opts[:from]
|
157
|
+
elsif !strict
|
158
|
+
value
|
159
|
+
end
|
160
|
+
|
161
|
+
mapper = foobara_domain_mapper_registry.lookup(from:, to:, strict:)
|
162
|
+
|
163
|
+
mapper&.call(value)
|
164
|
+
end
|
165
|
+
|
166
|
+
def foobara_domain_map!(value, from: value, to: nil, strict: false)
|
167
|
+
mapper = foobara_domain_mapper_registry.lookup(from:, to:, strict:)
|
168
|
+
|
169
|
+
unless mapper
|
170
|
+
raise NoDomainMapperFoundError.new(value, from, to)
|
171
|
+
end
|
172
|
+
|
173
|
+
mapper.call(value)
|
174
|
+
end
|
175
|
+
|
176
|
+
def foobara_domain_mapper(mapper)
|
177
|
+
foobara_domain_mapper_registry(skip_check: true).register(mapper)
|
178
|
+
end
|
179
|
+
|
180
|
+
def foobara_domain_mapper_registry(skip_check: false)
|
181
|
+
Foobara::DomainMapper.foobara_process_domain_mappers unless skip_check
|
182
|
+
@foobara_domain_mapper_registry ||= DomainMapper::Registry.new
|
183
|
+
end
|
184
|
+
|
185
|
+
def foobara_domain_name
|
186
|
+
# TODO: does this work properly with prefixes?
|
187
|
+
@foobara_domain_name || scoped_name
|
188
|
+
end
|
189
|
+
|
190
|
+
def foobara_full_domain_name
|
191
|
+
@foobara_full_domain_name || scoped_full_name
|
192
|
+
end
|
193
|
+
|
194
|
+
def foobara_full_domain_symbol
|
195
|
+
Util.underscore_sym(foobara_full_domain_name)
|
196
|
+
end
|
197
|
+
|
198
|
+
def foobara_organization_name
|
199
|
+
foobara_organization&.foobara_organization_name
|
200
|
+
end
|
201
|
+
|
202
|
+
def foobara_full_organization_name
|
203
|
+
foobara_organization&.foobara_full_organization_name
|
204
|
+
end
|
205
|
+
|
206
|
+
def foobara_organization
|
207
|
+
parent = foobara_parent_namespace
|
208
|
+
|
209
|
+
while parent
|
210
|
+
return parent if parent&.foobara_organization?
|
211
|
+
|
212
|
+
# TODO: we really should test this path
|
213
|
+
# :nocov:
|
214
|
+
parent = parent.foobara_parent_namespace
|
215
|
+
# :nocov:
|
216
|
+
end || GlobalOrganization
|
217
|
+
end
|
218
|
+
|
219
|
+
def foobara_domain?
|
220
|
+
true
|
221
|
+
end
|
222
|
+
|
223
|
+
# TODO: kill this off
|
224
|
+
def foobara_type_builder
|
225
|
+
@foobara_type_builder ||= begin
|
226
|
+
accesses = self == GlobalDomain ? [] : GlobalDomain.foobara_type_builder
|
227
|
+
TypeDeclarations::TypeBuilder.new(foobara_full_domain_name, accesses:)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def foobara_type_from_declaration(...)
|
232
|
+
Foobara::Namespace.use self do
|
233
|
+
foobara_type_builder.type_for_declaration(...)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def foobara_type_from_strict_stringified_declaration(...)
|
238
|
+
Foobara::Namespace.use self do
|
239
|
+
foobara_type_builder.type_for_strict_stringified_declaration(...)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def foobara_type_from_strict_declaration(...)
|
244
|
+
Foobara::Namespace.use self do
|
245
|
+
foobara_type_builder.type_for_strict_declaration(...)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def foobara_command_classes
|
250
|
+
foobara_all_command(mode: Namespace::LookupMode::DIRECT)
|
251
|
+
end
|
252
|
+
|
253
|
+
def foobara_register_type(type_symbol, *type_declaration_bits, &block)
|
254
|
+
type = if block.nil? && type_declaration_bits.size == 1 && type_declaration_bits.first.is_a?(Types::Type)
|
255
|
+
type_declaration_bits.first
|
256
|
+
else
|
257
|
+
foobara_type_from_declaration(*type_declaration_bits, &block)
|
258
|
+
end
|
259
|
+
|
260
|
+
if type_symbol.is_a?(::Array)
|
261
|
+
type.scoped_path = type_symbol
|
262
|
+
type.type_symbol = type_symbol.join("::")
|
263
|
+
else
|
264
|
+
type_symbol = type_symbol.to_s if type_symbol.is_a?(::Symbol)
|
265
|
+
|
266
|
+
type.scoped_path = type_symbol.split("::")
|
267
|
+
type.type_symbol = type_symbol.to_sym
|
268
|
+
end
|
269
|
+
|
270
|
+
type.foobara_parent_namespace ||= self
|
271
|
+
foobara_register(type)
|
272
|
+
|
273
|
+
_set_type_constant(type)
|
274
|
+
|
275
|
+
type
|
276
|
+
end
|
277
|
+
|
278
|
+
def foobara_register_model(model_class, reregister: false)
|
279
|
+
type = model_class.model_type
|
280
|
+
|
281
|
+
if type.scoped_path_set? && foobara_registered?(type.scoped_full_name, mode: Namespace::LookupMode::DIRECT)
|
282
|
+
if reregister
|
283
|
+
foobara_unregister(type)
|
284
|
+
else
|
285
|
+
# :nocov:
|
286
|
+
raise AlreadyRegisteredError, "Already registered: #{type.inspect}"
|
287
|
+
# :nocov:
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
foobara_register(type)
|
292
|
+
type.foobara_parent_namespace = self
|
293
|
+
|
294
|
+
type.target_class
|
295
|
+
end
|
296
|
+
|
297
|
+
def foobara_reregister_model(model_class)
|
298
|
+
foobara_register_model(model_class, reregister: true)
|
299
|
+
end
|
300
|
+
|
301
|
+
# TODO: kill this off
|
302
|
+
def foobara_register_entity(name, *args, &block)
|
303
|
+
# TODO: introduce a Namespace#scope method to simplify this a bit
|
304
|
+
Foobara::Namespace.use self do
|
305
|
+
if block
|
306
|
+
args = [TypeDeclarations::Dsl::Attributes.to_declaration(&block), *args]
|
307
|
+
end
|
308
|
+
|
309
|
+
attributes_type_declaration, *args = args
|
310
|
+
|
311
|
+
model_base_class, description = case args.size
|
312
|
+
when 0
|
313
|
+
[]
|
314
|
+
when 1, 2
|
315
|
+
arg, other = args
|
316
|
+
|
317
|
+
if args.first.is_a?(::String)
|
318
|
+
[other, arg]
|
319
|
+
else
|
320
|
+
args
|
321
|
+
end
|
322
|
+
else
|
323
|
+
# :nocov:
|
324
|
+
raise ArgumentError, "Too many arguments"
|
325
|
+
# :nocov:
|
326
|
+
end
|
327
|
+
|
328
|
+
if model_base_class
|
329
|
+
attributes_type_declaration = TypeDeclarations::Attributes.merge(
|
330
|
+
model_base_class.attributes_type.declaration_data,
|
331
|
+
attributes_type_declaration
|
332
|
+
)
|
333
|
+
end
|
334
|
+
|
335
|
+
handler = foobara_type_builder.handler_for_class(
|
336
|
+
Foobara::TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
337
|
+
)
|
338
|
+
|
339
|
+
attributes_type = handler.type_for_declaration(attributes_type_declaration)
|
340
|
+
|
341
|
+
# TODO: reuse the model_base_class primary key if it has one...
|
342
|
+
primary_key = attributes_type.element_types.keys.first
|
343
|
+
|
344
|
+
foobara_type_builder.type_for_declaration(
|
345
|
+
Util.remove_blank(
|
346
|
+
type: :entity,
|
347
|
+
name:,
|
348
|
+
model_base_class:,
|
349
|
+
attributes_declaration: attributes_type_declaration,
|
350
|
+
model_module: self,
|
351
|
+
primary_key:,
|
352
|
+
description:,
|
353
|
+
_desugarized: { type_absolutified: true }
|
354
|
+
)
|
355
|
+
).target_class
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
def foobara_register_entities(entity_names_to_attributes)
|
360
|
+
entity_names_to_attributes.each_pair do |entity_name, attributes_type_declaration|
|
361
|
+
foobara_register_entity(entity_name, attributes_type_declaration)
|
362
|
+
end
|
363
|
+
|
364
|
+
nil
|
365
|
+
end
|
366
|
+
|
367
|
+
def foobara_depends_on?(other_domain)
|
368
|
+
other_domain = Domain.to_domain(other_domain)
|
369
|
+
|
370
|
+
# TODO: Feels awkward to have to check if we're the global domain or not here.
|
371
|
+
# Also awkward to check if the other domain is global.
|
372
|
+
# Unclear what the solution is. To fix other domain check could just automatically call
|
373
|
+
# depends_on with the global domain in .foobara_domain! but not as clear how to fix the check
|
374
|
+
# against self.
|
375
|
+
self == GlobalDomain || other_domain == self || other_domain == GlobalDomain ||
|
376
|
+
foobara_depends_on.include?(other_domain.foobara_full_domain_name)
|
377
|
+
end
|
378
|
+
|
379
|
+
def foobara_depends_on(*domains)
|
380
|
+
if domains.empty?
|
381
|
+
return @foobara_depends_on ||= Set.new
|
382
|
+
end
|
383
|
+
|
384
|
+
if domains.length == 1
|
385
|
+
domains = Util.array(domains.first)
|
386
|
+
end
|
387
|
+
|
388
|
+
domains.each do |domain|
|
389
|
+
# It very likely could be a module extended with domain methods...
|
390
|
+
domain = Domain.to_domain(domain)
|
391
|
+
domain_name = domain.foobara_full_domain_name
|
392
|
+
|
393
|
+
if foobara_depends_on.include?(domain_name)
|
394
|
+
# :nocov:
|
395
|
+
raise AlreadyRegisteredDomainDependency, "Already registered #{domain_name} as a dependency of #{self}"
|
396
|
+
# :nocov:
|
397
|
+
end
|
398
|
+
|
399
|
+
foobara_depends_on_namespaces << domain
|
400
|
+
foobara_type_builder.accesses << domain.foobara_type_builder
|
401
|
+
|
402
|
+
foobara_depends_on << domain_name
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
# TODO: can we kill this skip concept?
|
407
|
+
def foobara_manifest(to_include:)
|
408
|
+
depends_on = foobara_depends_on.map do |name|
|
409
|
+
domain = Domain.to_domain(name)
|
410
|
+
to_include << domain
|
411
|
+
domain.foobara_manifest_reference
|
412
|
+
end.sort
|
413
|
+
|
414
|
+
commands = foobara_all_command(mode: Namespace::LookupMode::DIRECT).map do |command_class|
|
415
|
+
to_include << command_class
|
416
|
+
command_class.foobara_manifest_reference
|
417
|
+
end.sort
|
418
|
+
|
419
|
+
types = foobara_all_type(mode: Namespace::LookupMode::DIRECT).map do |type|
|
420
|
+
to_include << type
|
421
|
+
type.foobara_manifest_reference
|
422
|
+
end.sort
|
423
|
+
|
424
|
+
manifest = super.merge(commands:, types:)
|
425
|
+
|
426
|
+
unless depends_on.empty?
|
427
|
+
manifest[:depends_on] = depends_on
|
428
|
+
end
|
429
|
+
|
430
|
+
manifest
|
431
|
+
end
|
432
|
+
|
433
|
+
def _set_type_constant(type)
|
434
|
+
domain = if scoped_full_path.empty?
|
435
|
+
GlobalDomain
|
436
|
+
else
|
437
|
+
self
|
438
|
+
end
|
439
|
+
|
440
|
+
path = type.scoped_path
|
441
|
+
if path.first == "Types"
|
442
|
+
path = path[1..]
|
443
|
+
end
|
444
|
+
|
445
|
+
types_mod = if domain.const_defined?(:Types)
|
446
|
+
domain.const_get(:Types)
|
447
|
+
else
|
448
|
+
domain.const_set(:Types, Module.new)
|
449
|
+
end
|
450
|
+
|
451
|
+
if type.scoped_prefix
|
452
|
+
const_name = [types_mod.name, *path[0..-2]].join("::")
|
453
|
+
types_mod = Util.make_module_p(const_name, tag: true)
|
454
|
+
end
|
455
|
+
|
456
|
+
# TODO: dry this up
|
457
|
+
if type.scoped_short_name =~ /\A[a-z]/
|
458
|
+
unless types_mod.respond_to?(type.scoped_short_name)
|
459
|
+
types_mod.singleton_class.define_method type.scoped_short_name do
|
460
|
+
type
|
461
|
+
end
|
462
|
+
|
463
|
+
unless types_mod.instance_variable_defined?(:@foobara_lowercase_constants)
|
464
|
+
types_mod.instance_variable_set(:@foobara_lowercase_constants, [])
|
465
|
+
end
|
466
|
+
|
467
|
+
types_mod.instance_variable_get(:@foobara_lowercase_constants) << type.scoped_short_name
|
468
|
+
end
|
469
|
+
elsif types_mod.const_defined?(type.scoped_short_name, false)
|
470
|
+
existing_value = types_mod.const_get(type.scoped_short_name)
|
471
|
+
existing_value_type = if existing_value.is_a?(::Class) && existing_value < Foobara::Model
|
472
|
+
# TODO: test this code path
|
473
|
+
# :nocov:
|
474
|
+
existing_value.model_type
|
475
|
+
# :nocov:
|
476
|
+
else
|
477
|
+
existing_value
|
478
|
+
end
|
479
|
+
|
480
|
+
if existing_value_type != type
|
481
|
+
if existing_value.is_a?(::Module) && !existing_value.is_a?(::Class) &&
|
482
|
+
existing_value.instance_variable_get(:@foobara_created_via_make_class) &&
|
483
|
+
# not allowing lower-case "constants" to be namespaces
|
484
|
+
type.extends?("::model")
|
485
|
+
|
486
|
+
types_mod.send(:remove_const, type.scoped_short_name)
|
487
|
+
types_mod.const_set(type.scoped_short_name, type.target_class)
|
488
|
+
|
489
|
+
DomainModuleExtension._copy_constants(existing_value, type.target_class)
|
490
|
+
else
|
491
|
+
# :nocov:
|
492
|
+
raise CannotSetTypeConstantError,
|
493
|
+
"Already defined constant #{types_mod.name}::#{type.scoped_short_name}"
|
494
|
+
# :nocov:
|
495
|
+
end
|
496
|
+
end
|
497
|
+
else
|
498
|
+
symbol = type.scoped_short_name
|
499
|
+
|
500
|
+
if type.extends?("::model")
|
501
|
+
type = type.target_class
|
502
|
+
end
|
503
|
+
|
504
|
+
types_mod.const_set(symbol, type)
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|