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,35 @@
|
|
1
|
+
require_relative "model"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Manifest
|
5
|
+
class Entity < Model
|
6
|
+
self.category_symbol = :type
|
7
|
+
|
8
|
+
optional_key(:associations, default: {})
|
9
|
+
|
10
|
+
alias entity_manifest model_manifest
|
11
|
+
|
12
|
+
def has_associations?
|
13
|
+
associations && !associations.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def primary_key_name
|
17
|
+
primary_key_attribute.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def primary_key_type
|
21
|
+
@primary_key_type ||= TypeDeclaration.new(root_manifest, [*path, :primary_key_type])
|
22
|
+
end
|
23
|
+
|
24
|
+
def attribute_names
|
25
|
+
super - [primary_key_name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def associations
|
29
|
+
@associations ||= self[:associations].to_h do |path_key, type_name|
|
30
|
+
[path_key.to_sym, Type.new(root_manifest, [:type, type_name])]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Manifest
|
3
|
+
class Error < BaseManifest
|
4
|
+
self.category_symbol = :error
|
5
|
+
|
6
|
+
def error_manifest
|
7
|
+
relevant_manifest
|
8
|
+
end
|
9
|
+
|
10
|
+
def symbol
|
11
|
+
super.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_name
|
15
|
+
scoped_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def full_error_name
|
19
|
+
scoped_full_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def abstract
|
23
|
+
self[:abstract]
|
24
|
+
end
|
25
|
+
|
26
|
+
def types_depended_on
|
27
|
+
@types_depended_on ||= self[:types_depended_on].map do |type_reference|
|
28
|
+
Type.new(root_manifest, [:type, type_reference])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative "type"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Manifest
|
5
|
+
class Model < Type
|
6
|
+
self.category_symbol = :type
|
7
|
+
|
8
|
+
alias model_manifest relevant_manifest
|
9
|
+
|
10
|
+
def attributes_type
|
11
|
+
Attributes.new(root_manifest, [*path, :attributes_type])
|
12
|
+
end
|
13
|
+
|
14
|
+
def attribute_names
|
15
|
+
attributes_type.attribute_names
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: rename
|
19
|
+
def has_associations?(type = attributes_type)
|
20
|
+
case type
|
21
|
+
when Entity
|
22
|
+
true
|
23
|
+
when Model
|
24
|
+
has_associations?(type.attributes_type)
|
25
|
+
when Attributes
|
26
|
+
type.attribute_declarations.values.any? do |attribute_declaration|
|
27
|
+
has_associations?(attribute_declaration)
|
28
|
+
end
|
29
|
+
when Array
|
30
|
+
has_associations?(type.element_type)
|
31
|
+
when TypeDeclaration
|
32
|
+
has_associations?(type.to_type)
|
33
|
+
when Type
|
34
|
+
type.entity?
|
35
|
+
else
|
36
|
+
# :nocov:
|
37
|
+
raise "not sure how to proceed with #{type}"
|
38
|
+
# :nocov:
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Manifest
|
3
|
+
class Organization < BaseManifest
|
4
|
+
self.category_symbol = :organization
|
5
|
+
|
6
|
+
def organization_manifest
|
7
|
+
relevant_manifest
|
8
|
+
end
|
9
|
+
|
10
|
+
def domains
|
11
|
+
@domains ||= DataPath.value_at(:domains, organization_manifest).map do |key|
|
12
|
+
Domain.new(root_manifest, [:domain, key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def commands
|
17
|
+
domains.map(&:commands).flatten
|
18
|
+
end
|
19
|
+
|
20
|
+
def types
|
21
|
+
domains.map(&:types).flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
def entities
|
25
|
+
domains.map(&:entities).flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
def models
|
29
|
+
domains.map(&:models).flatten
|
30
|
+
end
|
31
|
+
|
32
|
+
def global?
|
33
|
+
reference == "global_organization"
|
34
|
+
end
|
35
|
+
|
36
|
+
def organization_name
|
37
|
+
scoped_name
|
38
|
+
end
|
39
|
+
|
40
|
+
def full_organization_name
|
41
|
+
scoped_full_name
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Manifest
|
3
|
+
class PossibleError < BaseManifest
|
4
|
+
optional_key(:path, default: [])
|
5
|
+
|
6
|
+
def possible_error_manifest
|
7
|
+
relevant_manifest
|
8
|
+
end
|
9
|
+
|
10
|
+
def error
|
11
|
+
Error.new(root_manifest, [:error, DataPath.value_at([:error], possible_error_manifest)])
|
12
|
+
end
|
13
|
+
|
14
|
+
def processor_manifest_data
|
15
|
+
self[:processor_manifest_data]
|
16
|
+
end
|
17
|
+
|
18
|
+
def manually_added
|
19
|
+
self[:manually_added]
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: this has to die
|
23
|
+
|
24
|
+
# oops, shadowed the convenience method
|
25
|
+
def _path
|
26
|
+
method_missing(:path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Manifest
|
3
|
+
class RootManifest < BaseManifest
|
4
|
+
include TruncatedInspect
|
5
|
+
|
6
|
+
attr_accessor :root_manifest
|
7
|
+
|
8
|
+
def initialize(root_manifest)
|
9
|
+
super(root_manifest, [])
|
10
|
+
end
|
11
|
+
|
12
|
+
def organizations
|
13
|
+
@organizations ||= DataPath.value_at(:organization, root_manifest).keys.map do |reference|
|
14
|
+
Organization.new(root_manifest, [:organization, reference])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def domains
|
19
|
+
@domains ||= DataPath.value_at(:domain, root_manifest).keys.map do |reference|
|
20
|
+
Domain.new(root_manifest, [:domain, reference])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def commands
|
25
|
+
organizations.map(&:commands).flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
def types
|
29
|
+
@types ||= DataPath.value_at(:type, root_manifest).keys.map do |reference|
|
30
|
+
Type.new(root_manifest, [:type, reference])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def entities
|
35
|
+
organizations.map(&:entities).flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def models
|
39
|
+
organizations.map(&:models).flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
def errors
|
43
|
+
@errors ||= DataPath.value_at(:error, root_manifest).keys.map do |reference|
|
44
|
+
Error.new(root_manifest, [:error, reference])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def entity_by_name(name)
|
49
|
+
type = type_by_name(name)
|
50
|
+
|
51
|
+
raise "#{name} is not an entity" unless type.entity?
|
52
|
+
|
53
|
+
type
|
54
|
+
end
|
55
|
+
|
56
|
+
def model_by_name(name)
|
57
|
+
type = type_by_name(name)
|
58
|
+
|
59
|
+
raise "#{name} is not a model" unless type.model?
|
60
|
+
|
61
|
+
type
|
62
|
+
end
|
63
|
+
|
64
|
+
def type_by_name(name)
|
65
|
+
Type.new(root_manifest, [:type, name])
|
66
|
+
end
|
67
|
+
|
68
|
+
def command_by_name(name)
|
69
|
+
Command.new(root_manifest, [:command, name])
|
70
|
+
end
|
71
|
+
|
72
|
+
def domain_by_name(name)
|
73
|
+
Domain.new(root_manifest, [:domain, name])
|
74
|
+
end
|
75
|
+
|
76
|
+
def organization_by_name(name)
|
77
|
+
Organization.new(root_manifest, [:organization, name])
|
78
|
+
end
|
79
|
+
|
80
|
+
# TODO: this isn't quite right. If the thing is there but is nil or false, this should be truthy.
|
81
|
+
def contains?(reference, category)
|
82
|
+
DataPath.value_at([category, reference], root_manifest)
|
83
|
+
end
|
84
|
+
|
85
|
+
def lookup_path(category, reference)
|
86
|
+
path = [category, reference]
|
87
|
+
raw_manifest = DataPath.value_at(path, root_manifest)
|
88
|
+
|
89
|
+
if raw_manifest
|
90
|
+
return self.class.category_to_manifest_class(category).new(root_manifest, path)
|
91
|
+
end
|
92
|
+
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def lookup(reference)
|
97
|
+
prioritized_categories = %i[command type error domain organization processor processor_class]
|
98
|
+
|
99
|
+
prioritized_categories.each do |category|
|
100
|
+
path = [category, reference]
|
101
|
+
raw_manifest = DataPath.value_at(path, root_manifest)
|
102
|
+
|
103
|
+
if raw_manifest
|
104
|
+
return self.class.category_to_manifest_class(category).new(root_manifest, path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Manifest
|
3
|
+
# TODO: override new to return Entity when it's an entity
|
4
|
+
class Type < BaseManifest
|
5
|
+
self.category_symbol = :type
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def new(root_manifest, path)
|
9
|
+
type = super(root_manifest, path)
|
10
|
+
|
11
|
+
if self == Type
|
12
|
+
if type.entity?
|
13
|
+
type = Entity.new(type.root_manifest, type.path)
|
14
|
+
elsif type.model?
|
15
|
+
type = Model.new(type.root_manifest, type.path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def type_manifest
|
24
|
+
relevant_manifest
|
25
|
+
end
|
26
|
+
|
27
|
+
def entity?
|
28
|
+
type = base_type
|
29
|
+
|
30
|
+
while type
|
31
|
+
return true if type.reference.to_sym == :entity
|
32
|
+
|
33
|
+
type = type.base_type
|
34
|
+
end
|
35
|
+
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def model?
|
40
|
+
return false if reference == "entity"
|
41
|
+
|
42
|
+
type = base_type
|
43
|
+
|
44
|
+
while type
|
45
|
+
return true if type.reference.to_sym == :model
|
46
|
+
|
47
|
+
type = type.base_type
|
48
|
+
end
|
49
|
+
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def base_type
|
54
|
+
base_type_symbol = self[:base_type]
|
55
|
+
|
56
|
+
if base_type_symbol
|
57
|
+
Type.new(root_manifest, [:type, self[:base_type]])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def target_class
|
62
|
+
if target_classes.size != 1
|
63
|
+
# :nocov:
|
64
|
+
raise "Can only use #target_class for types with one target class but #{name} has #{target_classes.size}"
|
65
|
+
# :nocov:
|
66
|
+
end
|
67
|
+
|
68
|
+
target_classes.first
|
69
|
+
end
|
70
|
+
|
71
|
+
def types_depended_on
|
72
|
+
@types_depended_on ||= self[:types_depended_on].map do |type_reference|
|
73
|
+
Type.new(root_manifest, [:type, type_reference])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def type_name
|
78
|
+
scoped_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def full_type_name
|
82
|
+
scoped_full_name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative "base_manifest"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Manifest
|
5
|
+
class TypeDeclaration < BaseManifest
|
6
|
+
optional_keys(:allow_nil, :one_of)
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def new(root_manifest, path)
|
10
|
+
type_declaration = super(root_manifest, path)
|
11
|
+
|
12
|
+
if self == TypeDeclaration
|
13
|
+
case type_declaration.type.to_sym
|
14
|
+
when :attributes
|
15
|
+
Attributes.new(type_declaration.root_manifest, type_declaration.path)
|
16
|
+
when :array
|
17
|
+
Array.new(type_declaration.root_manifest, type_declaration.path)
|
18
|
+
else
|
19
|
+
type_declaration
|
20
|
+
end
|
21
|
+
else
|
22
|
+
type_declaration
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# rubocop:disable Naming/MemoizedInstanceVariableName
|
28
|
+
# TODO: create an Attribute class to encapsulate this situation
|
29
|
+
def attribute?
|
30
|
+
return @is_attribute if defined?(@is_attribute)
|
31
|
+
|
32
|
+
parent_path_atom = path[2..][-2]
|
33
|
+
@is_attribute = [:element_type_declarations, "element_type_declarations"].include?(parent_path_atom)
|
34
|
+
end
|
35
|
+
# rubocop:enable Naming/MemoizedInstanceVariableName
|
36
|
+
|
37
|
+
def parent_attributes
|
38
|
+
return @parent_attributes if defined?(@parent_attributes)
|
39
|
+
|
40
|
+
raise "Not an attribute" unless attribute?
|
41
|
+
|
42
|
+
@parent_attributes = Attributes.new(root_manifest, path[0..-3])
|
43
|
+
end
|
44
|
+
|
45
|
+
def attribute_name
|
46
|
+
return @attribute_name if defined?(@attribute_name)
|
47
|
+
|
48
|
+
raise "Not an attribute" unless attribute?
|
49
|
+
|
50
|
+
@attribute_name = path[-1]
|
51
|
+
end
|
52
|
+
|
53
|
+
def required?
|
54
|
+
parent_attributes.required?(attribute_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def default
|
58
|
+
parent_attributes.default_for(attribute_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def allows_nil?
|
62
|
+
allow_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def type_declaration_manifest
|
66
|
+
relevant_manifest
|
67
|
+
end
|
68
|
+
|
69
|
+
def attributes?
|
70
|
+
type.to_sym == :attributes
|
71
|
+
end
|
72
|
+
|
73
|
+
def array?
|
74
|
+
type.to_sym == :array
|
75
|
+
end
|
76
|
+
|
77
|
+
def model?
|
78
|
+
return @model if defined?(@model)
|
79
|
+
|
80
|
+
@model = to_type.model?
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_model
|
84
|
+
raise "not an model" unless model?
|
85
|
+
raise "model extension instead of an model" unless relevant_manifest.size == 1
|
86
|
+
|
87
|
+
type = to_type
|
88
|
+
|
89
|
+
raise "not an model" unless type.model?
|
90
|
+
|
91
|
+
type
|
92
|
+
end
|
93
|
+
|
94
|
+
def entity?
|
95
|
+
return @entity if defined?(@entity)
|
96
|
+
|
97
|
+
@entity = to_type.entity?
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_entity
|
101
|
+
raise "not an entity" unless entity?
|
102
|
+
raise "entity extension instead of an entity" unless relevant_manifest.size == 1
|
103
|
+
|
104
|
+
type = to_type
|
105
|
+
|
106
|
+
raise "not an entity" unless type.entity?
|
107
|
+
|
108
|
+
type
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_type
|
112
|
+
# awkward??
|
113
|
+
@to_type ||= find_type(self)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "date"
|
2
|
+
require "time"
|
3
|
+
require "bigdecimal"
|
4
|
+
|
5
|
+
module Foobara
|
6
|
+
class Model
|
7
|
+
class << self
|
8
|
+
def install!
|
9
|
+
TypeDeclarations.register_type_declaration(TypeDeclarations::Handlers::ExtendModelTypeDeclaration.new)
|
10
|
+
TypeDeclarations.register_type_declaration(TypeDeclarations::Handlers::ExtendRegisteredModelTypeDeclaration.new)
|
11
|
+
|
12
|
+
atomic_duck = Namespace.global.foobara_lookup_type!(:atomic_duck)
|
13
|
+
BuiltinTypes.build_and_register!(:model, atomic_duck, nil)
|
14
|
+
# address = build_and_register!(:address, model)
|
15
|
+
# us_address = build_and_register!(:us_address, model)
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_all
|
19
|
+
install!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Model
|
3
|
+
module Concerns
|
4
|
+
module Reflection
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def foobara_manifest(to_include:)
|
9
|
+
Util.remove_blank(
|
10
|
+
attributes_type: attributes_type.declaration_data,
|
11
|
+
organization_name:,
|
12
|
+
domain_name:,
|
13
|
+
model_name:,
|
14
|
+
model_base_class: model_type.declaration_data[:model_base_class],
|
15
|
+
model_class: model_type.declaration_data[:model_class]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Model
|
3
|
+
module Concerns
|
4
|
+
module Types
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
foobara_delegate :attributes_type, to: :class
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
attr_reader :model_type
|
11
|
+
attr_writer :attributes_type
|
12
|
+
|
13
|
+
def attributes(*args, **opts, &)
|
14
|
+
new_type = domain.foobara_type_from_declaration(*args, **opts, &)
|
15
|
+
|
16
|
+
unless new_type.extends?(BuiltinTypes[:attributes])
|
17
|
+
# :nocov:
|
18
|
+
raise ArgumentError, "Expected #{args} #{opts} to extend :attributes " \
|
19
|
+
"but instead it resulted in: #{new_type.declaration_data}"
|
20
|
+
# :nocov:
|
21
|
+
end
|
22
|
+
|
23
|
+
existing_type = attributes_type
|
24
|
+
|
25
|
+
if existing_type
|
26
|
+
declaration = TypeDeclarations::Attributes.merge(
|
27
|
+
existing_type.declaration_data,
|
28
|
+
new_type.declaration_data
|
29
|
+
)
|
30
|
+
|
31
|
+
new_type = domain.foobara_type_from_declaration(declaration)
|
32
|
+
end
|
33
|
+
|
34
|
+
self.attributes_type = new_type
|
35
|
+
|
36
|
+
set_model_type
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_model_type
|
40
|
+
return if abstract?
|
41
|
+
|
42
|
+
if attributes_type
|
43
|
+
declaration = type_declaration(attributes_type.declaration_data)
|
44
|
+
|
45
|
+
domain.foobara_type_from_declaration(declaration)
|
46
|
+
|
47
|
+
unless @model_type
|
48
|
+
# :nocov:
|
49
|
+
raise "Expected model type to automatically be registered"
|
50
|
+
# :nocov:
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def type_declaration(attributes_declaration)
|
56
|
+
if name.start_with?(closest_namespace_module.name)
|
57
|
+
model_module_name = closest_namespace_module.name
|
58
|
+
model_name = name.gsub(/^#{closest_namespace_module.name}::/, "")
|
59
|
+
else
|
60
|
+
model_module_name = nil
|
61
|
+
model_name = name
|
62
|
+
end
|
63
|
+
|
64
|
+
Util.remove_blank(
|
65
|
+
type: :model,
|
66
|
+
name: model_name,
|
67
|
+
model_module: model_module_name,
|
68
|
+
model_class: self,
|
69
|
+
model_base_class: superclass,
|
70
|
+
attributes_declaration:,
|
71
|
+
description:,
|
72
|
+
_desugarized: { type_absolutified: true }
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def attributes_type
|
77
|
+
return @attributes_type if @attributes_type
|
78
|
+
|
79
|
+
@attributes_type = if model_type
|
80
|
+
model_type.element_types
|
81
|
+
elsif ancestors.find { |ancestor| ancestor < Model }
|
82
|
+
superclass.attributes_type
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def model_type=(model_type)
|
87
|
+
@model_type = model_type
|
88
|
+
|
89
|
+
attributes_type.element_types.each_key do |attribute_name|
|
90
|
+
define_method attribute_name do
|
91
|
+
read_attribute(attribute_name)
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: let's cache validation_errors and clobber caches when updating this for performance reasons
|
95
|
+
define_method "#{attribute_name}=" do |value|
|
96
|
+
write_attribute(attribute_name, value)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Model
|
4
|
+
module Casters
|
5
|
+
class Hash < Attributes::Casters::Hash
|
6
|
+
class << self
|
7
|
+
def requires_parent_declaration_data?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def cast(attributes)
|
13
|
+
model_class.new(super)
|
14
|
+
end
|
15
|
+
|
16
|
+
def model_class
|
17
|
+
Object.const_get(parent_declaration_data[:model_class])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|