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,51 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Reflection
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def depends_on
|
9
|
+
associations.values.map(&:target_class).uniq
|
10
|
+
end
|
11
|
+
|
12
|
+
def deep_depends_on
|
13
|
+
types = deep_associations.sort_by do |path, _type|
|
14
|
+
[DataPath.new(path).path.size, path]
|
15
|
+
end.map(&:last)
|
16
|
+
|
17
|
+
types.map(&:target_class).uniq
|
18
|
+
end
|
19
|
+
|
20
|
+
def foobara_manifest(to_include:)
|
21
|
+
associations = self.associations.map do |(path, type)|
|
22
|
+
entity_class = type.target_class
|
23
|
+
entity_name = entity_class.full_entity_name
|
24
|
+
|
25
|
+
[path, entity_name]
|
26
|
+
end.sort.to_h
|
27
|
+
|
28
|
+
deep_associations = self.deep_associations.map do |(path, type)|
|
29
|
+
entity_class = type.target_class
|
30
|
+
entity_name = entity_class.full_entity_name
|
31
|
+
|
32
|
+
[path, entity_name]
|
33
|
+
end.sort.to_h
|
34
|
+
|
35
|
+
super.merge(
|
36
|
+
Util.remove_blank(
|
37
|
+
depends_on: depends_on.map(&:full_entity_name),
|
38
|
+
deep_depends_on: deep_depends_on.map(&:full_entity_name),
|
39
|
+
associations:,
|
40
|
+
deep_associations:,
|
41
|
+
entity_name:,
|
42
|
+
primary_key_attribute:,
|
43
|
+
primary_key_type: attributes_type.declaration_data[:element_type_declarations][primary_key_attribute]
|
44
|
+
)
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Transactions
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def current_transaction_table
|
9
|
+
Foobara::Persistence.current_transaction_table!(self)
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_transaction
|
13
|
+
Foobara::Persistence.current_transaction!(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def transaction(mode: nil, skip_dependent_transactions: false, &)
|
17
|
+
if skip_dependent_transactions
|
18
|
+
entity_base.transaction(mode, &)
|
19
|
+
else
|
20
|
+
Foobara::Persistence.transaction(
|
21
|
+
self, *deep_depends_on,
|
22
|
+
mode:,
|
23
|
+
&
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Types
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def entity_type
|
9
|
+
model_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def type_declaration(...)
|
13
|
+
raise "No primary key set yet" unless primary_key_attribute
|
14
|
+
|
15
|
+
super.merge(type: :entity, primary_key: primary_key_attribute)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_model_type
|
19
|
+
if primary_key_attribute
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def primary_key_type
|
25
|
+
@primary_key_type ||= attributes_type.element_types[primary_key_attribute]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
class CannotConvertRecordWithoutPrimaryKeyToJsonError < StandardError; end
|
4
|
+
|
5
|
+
include Concerns::Callbacks
|
6
|
+
include Concerns::Associations
|
7
|
+
include Concerns::Transactions
|
8
|
+
include Concerns::Queries
|
9
|
+
include Concerns::Types
|
10
|
+
include Concerns::Attributes
|
11
|
+
include Concerns::PrimaryKey
|
12
|
+
include Concerns::Persistence
|
13
|
+
include Concerns::Initialization
|
14
|
+
include Concerns::Reflection
|
15
|
+
|
16
|
+
class << self
|
17
|
+
prepend NewPrepend
|
18
|
+
|
19
|
+
def full_entity_name
|
20
|
+
full_model_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def entity_name
|
24
|
+
model_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def allowed_subclass_opts
|
28
|
+
[:primary_key, *super]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
foobara_delegate :full_entity_name, :entity_name, to: :class
|
33
|
+
|
34
|
+
def dup
|
35
|
+
# TODO: Maybe raise instead?
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
# Should both records be required to be persisted to be considered equal when having matching primary keys?
|
41
|
+
# For now we will consider them equal but it could make sense to consider them not equal.
|
42
|
+
equal?(other) || (self.class == other.class && primary_key && primary_key == other.primary_key)
|
43
|
+
end
|
44
|
+
|
45
|
+
def hash
|
46
|
+
(primary_key || object_id).hash
|
47
|
+
end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
"<#{entity_name}:#{primary_key}>"
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_json(*_args)
|
54
|
+
primary_key&.to_json || raise(
|
55
|
+
CannotConvertRecordWithoutPrimaryKeyToJsonError,
|
56
|
+
"Cannot call record.to_json on unless record has a primary key. " \
|
57
|
+
"Consider instead calling record.attributes.to_json instead."
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Entity
|
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
|
+
symbolized_attributes = super
|
14
|
+
|
15
|
+
outcome = entity_class.attributes_type.process_value(symbolized_attributes)
|
16
|
+
|
17
|
+
if outcome.success?
|
18
|
+
entity_class.create(symbolized_attributes)
|
19
|
+
else
|
20
|
+
# we build an instance so that it can fail a validator later. But we already know we don't want to
|
21
|
+
# persist this thing. So use build instead of create.
|
22
|
+
entity_class.build(outcome.result)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def entity_class
|
27
|
+
Object.const_get(parent_declaration_data[:model_class])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Entity
|
4
|
+
module Validators
|
5
|
+
class AttributesDeclaration < Model::Validators::AttributesDeclaration
|
6
|
+
def applicable?(record)
|
7
|
+
record.created? || record.built?
|
8
|
+
end
|
9
|
+
|
10
|
+
# Why is this here in entity/ instead of in model/?
|
11
|
+
def possible_errors
|
12
|
+
return [] if parent_declaration_data == { type: :entity }
|
13
|
+
|
14
|
+
mutable = parent_declaration_data.key?(:mutable) ? parent_declaration_data[:mutable] : false
|
15
|
+
|
16
|
+
if parent_declaration_data.key?(:model_class)
|
17
|
+
Object.const_get(parent_declaration_data[:model_class]).possible_errors(mutable:)
|
18
|
+
elsif parent_declaration_data[:type] != :entity
|
19
|
+
model_type = type_for_declaration(parent_declaration_data[:type])
|
20
|
+
model_class = model_type.target_class
|
21
|
+
model_class.possible_errors(mutable:)
|
22
|
+
else
|
23
|
+
# :nocov:
|
24
|
+
raise "Missing :model_class in parent_declaration_data for #{parent_declaration_data}"
|
25
|
+
# :nocov:
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
# TODO: need primary key type declaration validator!
|
6
|
+
class AttributesHandlerDesugarizer < ExtendModelTypeDeclaration::AttributesHandlerDesugarizer
|
7
|
+
def expected_type_symbol
|
8
|
+
:entity
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class HashDesugarizer < TypeDeclarations::Desugarizer
|
6
|
+
def applicable?(sugary_type_declaration)
|
7
|
+
return false unless sugary_type_declaration.is_a?(::Hash)
|
8
|
+
return false unless Util.all_symbolizable_keys?(sugary_type_declaration)
|
9
|
+
|
10
|
+
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
11
|
+
|
12
|
+
type_symbol = sugary_type_declaration[:type] || sugary_type_declaration["type"]
|
13
|
+
return false unless type_symbol
|
14
|
+
|
15
|
+
type_symbol = type_symbol.to_sym if type_symbol.is_a?(::String)
|
16
|
+
|
17
|
+
return true if type_symbol == expected_type_symbol
|
18
|
+
|
19
|
+
if type_symbol.is_a?(::Symbol) && type_registered?(type_symbol)
|
20
|
+
type = Foobara.foobara_root_namespace.foobara_lookup_type(
|
21
|
+
type_symbol, mode: Namespace::LookupMode::ABSOLUTE
|
22
|
+
)
|
23
|
+
|
24
|
+
type&.extends?(BuiltinTypes[expected_type_symbol])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def expected_type_symbol
|
29
|
+
:entity
|
30
|
+
end
|
31
|
+
|
32
|
+
def desugarize(sugary_type_declaration)
|
33
|
+
Util.symbolize_keys(sugary_type_declaration)
|
34
|
+
end
|
35
|
+
|
36
|
+
def priority
|
37
|
+
Priority::FIRST + 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class ModelClassDesugarizer < ExtendModelTypeDeclaration::ModelClassDesugarizer
|
6
|
+
def expected_type_symbol
|
7
|
+
:entity
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_model_base_class
|
11
|
+
Foobara::Entity
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_model_class_args(model_module:, type_declaration:)
|
15
|
+
super.merge(primary_key: type_declaration[:primary_key])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class PrimaryKeyDesugarizer < Desugarizer
|
6
|
+
def applicable?(sugary_type_declaration)
|
7
|
+
primary_key = sugary_type_declaration[:primary_key]
|
8
|
+
|
9
|
+
primary_key.is_a?(::String)
|
10
|
+
end
|
11
|
+
|
12
|
+
def desugarize(sugary_type_declaration)
|
13
|
+
sugary_type_declaration.merge(primary_key: sugary_type_declaration[:primary_key].to_sym)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class ToTypeTransformer < ExtendModelTypeDeclaration::ToTypeTransformer
|
6
|
+
# TODO: move this to a more appropriate place
|
7
|
+
class EntityPrimaryKeyCaster < Value::Caster
|
8
|
+
class << self
|
9
|
+
def requires_declaration_data?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def entity_class
|
15
|
+
declaration_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def primary_key_type
|
19
|
+
entity_class.primary_key_type
|
20
|
+
end
|
21
|
+
|
22
|
+
def applicable?(value)
|
23
|
+
primary_key_type.applicable?(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def transform(primary_key)
|
27
|
+
entity_class.thunk(primary_key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def applies_message
|
31
|
+
primary_key_type.value_caster.applies_message
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def non_processor_keys
|
36
|
+
[:primary_key, *super]
|
37
|
+
end
|
38
|
+
|
39
|
+
def process_value(strict_declaration_type)
|
40
|
+
super.tap do |outcome|
|
41
|
+
if outcome.success?
|
42
|
+
type = outcome.result
|
43
|
+
|
44
|
+
entity_class = type.target_class
|
45
|
+
|
46
|
+
unless entity_class.primary_key_attribute
|
47
|
+
entity_class.primary_key(strict_declaration_type[:primary_key])
|
48
|
+
end
|
49
|
+
|
50
|
+
unless entity_class.can_be_created_through_casting?
|
51
|
+
type.casters = type.casters.reject do |caster|
|
52
|
+
caster.is_a?(Foobara::BuiltinTypes::Entity::Casters::Hash)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
type.casters << EntityPrimaryKeyCaster.new(entity_class)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class ValidatePrimaryKeyIsSymbol < TypeDeclarations::TypeDeclarationValidator
|
6
|
+
class PrimaryKeyNotSymbolError < TypeDeclarationError
|
7
|
+
class << self
|
8
|
+
def context_type_declaration
|
9
|
+
{
|
10
|
+
primary_key: :duck
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def applicable?(strict_type_declaration)
|
17
|
+
strict_type_declaration.key?(:primary_key)
|
18
|
+
end
|
19
|
+
|
20
|
+
def validation_errors(strict_type_declaration)
|
21
|
+
primary_key = strict_type_declaration[:primary_key]
|
22
|
+
unless primary_key.is_a?(::Symbol)
|
23
|
+
build_error(
|
24
|
+
message: "Expected #{primary_key} to be a symbol but it was a #{primary_key.class}",
|
25
|
+
context: {
|
26
|
+
primary_key:
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class ValidatePrimaryKeyPresent < TypeDeclarations::TypeDeclarationValidator
|
6
|
+
# TODO: seems like maybe we could actually check against types now...
|
7
|
+
# like make a type for primary_key: :symbol ??
|
8
|
+
class MissingPrimaryKeyError < TypeDeclarationError; end
|
9
|
+
|
10
|
+
def validation_errors(strict_type_declaration)
|
11
|
+
unless strict_type_declaration.key?(:primary_key)
|
12
|
+
build_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def error_message(_value)
|
17
|
+
"Missing required :primary_key to state which attribute is the primary key"
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_context(_value)
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration
|
5
|
+
class ValidatePrimaryKeyReferencesAttribute < TypeDeclarations::TypeDeclarationValidator
|
6
|
+
class InvalidPrimaryKeyError < TypeDeclarationError
|
7
|
+
class << self
|
8
|
+
def context_type_declaration
|
9
|
+
{
|
10
|
+
allowed_primary_keys: [:symbol],
|
11
|
+
primary_key: :symbol
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def applicable?(strict_type_declaration)
|
18
|
+
strict_type_declaration.key?(:primary_key) && strict_type_declaration[:primary_key].is_a?(::Symbol)
|
19
|
+
end
|
20
|
+
|
21
|
+
def validation_errors(strict_type_declaration)
|
22
|
+
allowed_primary_keys = strict_type_declaration[:attributes_declaration][:element_type_declarations].keys
|
23
|
+
|
24
|
+
primary_key = strict_type_declaration[:primary_key]
|
25
|
+
unless allowed_primary_keys.include?(primary_key)
|
26
|
+
build_error(
|
27
|
+
message: "Invalid primary key. Expected #{primary_key} to be one of #{allowed_primary_keys}",
|
28
|
+
context: { allowed_primary_keys:, primary_key: }
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module NewPrepend
|
4
|
+
# rubocop:disable Lint/UselessMethodDefinition
|
5
|
+
def new(...)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
# rubocop:enable Lint/UselessMethodDefinition
|
9
|
+
|
10
|
+
alias __private_new__ new
|
11
|
+
|
12
|
+
# rubocop:disable Lint/DuplicateMethods
|
13
|
+
def new(...)
|
14
|
+
# :nocov:
|
15
|
+
raise "Cannot initialize a #{name}. Use .create, .thunk, .loaded, or .build instead."
|
16
|
+
# :nocov:
|
17
|
+
end
|
18
|
+
# rubocop:enable Lint/DuplicateMethods
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
class NotFoundError < Foobara::RuntimeError
|
4
|
+
class << self
|
5
|
+
def not_found_error_class_name(data_path)
|
6
|
+
error_class_name = data_path.path.map { |part| part == :"#" ? "Collection" : Util.classify(part) }.join
|
7
|
+
"#{error_class_name}NotFoundError"
|
8
|
+
end
|
9
|
+
|
10
|
+
def subclass(mod, entity_class, data_path)
|
11
|
+
error_class_name = not_found_error_class_name(data_path)
|
12
|
+
|
13
|
+
# TODO: how would we avoid name collisions here??
|
14
|
+
Util.make_class("#{mod.name}::#{error_class_name}", self) do
|
15
|
+
# TODO: use Concern to change these into attr_accessor instead
|
16
|
+
singleton_class.define_method :data_path do
|
17
|
+
data_path
|
18
|
+
end
|
19
|
+
|
20
|
+
singleton_class.define_method :entity_class do
|
21
|
+
entity_class
|
22
|
+
end
|
23
|
+
|
24
|
+
singleton_class.define_method :context_type_declaration do
|
25
|
+
{
|
26
|
+
entity_class: :string, # TODO: we don't have a way to specify an exact value for a type
|
27
|
+
criteria: :duck, # TODO: find_by attributes unioned with primary key
|
28
|
+
data_path: :string # TODO: we don't have a way to specify an exact value for a type
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def data_path
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def context_type_declaration
|
39
|
+
{
|
40
|
+
entity_class: :string, # TODO: we don't have a way to specify an exact value for a type
|
41
|
+
criteria: :duck, # TODO: probably should be integer or string but no union types yet
|
42
|
+
data_path: :string # TODO: we don't have a way to specify an exact value for a type
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_accessor :data_path, :entity_class, :criteria
|
48
|
+
|
49
|
+
foobara_delegate :primary_key_attribute, :full_entity_name, to: :entity_class
|
50
|
+
|
51
|
+
def initialize(criteria, entity_class: self.class.entity_class, data_path: self.class.data_path)
|
52
|
+
self.criteria = criteria
|
53
|
+
self.entity_class = entity_class
|
54
|
+
self.data_path = data_path || ""
|
55
|
+
|
56
|
+
super(context:, message:)
|
57
|
+
end
|
58
|
+
|
59
|
+
def context
|
60
|
+
{
|
61
|
+
entity_class: full_entity_name,
|
62
|
+
criteria:,
|
63
|
+
data_path: data_path.to_s
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def message
|
68
|
+
"Could not find #{entity_class} for #{criteria}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module Foobara::Enumerated; end
|