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,170 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Attributes
|
5
|
+
class UnexpectedPrimaryKeyChangeError < StandardError; end
|
6
|
+
|
7
|
+
include Concern
|
8
|
+
|
9
|
+
def write_attribute_without_callbacks(attribute_name, value)
|
10
|
+
without_callbacks do
|
11
|
+
write_attribute(attribute_name, value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_attribute(attribute_name, value)
|
16
|
+
verify_not_hard_deleted!
|
17
|
+
|
18
|
+
with_changed_attribute_callbacks(attribute_name) do
|
19
|
+
load_if_necessary!(attribute_name)
|
20
|
+
|
21
|
+
attribute_name = attribute_name.to_sym
|
22
|
+
|
23
|
+
if attribute_name == primary_key_attribute
|
24
|
+
if value.nil?
|
25
|
+
# :nocov:
|
26
|
+
raise "Primary key cannot be set to a blank value"
|
27
|
+
# :nocov:
|
28
|
+
end
|
29
|
+
|
30
|
+
if value.is_a?(::String) && value.empty?
|
31
|
+
# :nocov:
|
32
|
+
raise "Primary key cannot be set to a blank value"
|
33
|
+
# :nocov:
|
34
|
+
end
|
35
|
+
|
36
|
+
if value.is_a?(::Symbol) && value.to_s.empty?
|
37
|
+
# :nocov:
|
38
|
+
raise "Primary key cannot be set to a blank value"
|
39
|
+
# :nocov:
|
40
|
+
end
|
41
|
+
|
42
|
+
write_attribute!(attribute_name, value)
|
43
|
+
else
|
44
|
+
attribute_name = attribute_name.to_sym
|
45
|
+
# This is a bit of a problem when creating invalid models from attributes...
|
46
|
+
# feels like we should do the best we can instead of not casting it at all. That is, better to have
|
47
|
+
# an invalid Model instance than a hash when a Model is expected.
|
48
|
+
# How do we go about doing that?
|
49
|
+
outcome = cast_attribute(attribute_name, value)
|
50
|
+
attributes[attribute_name] = outcome.success? ? outcome.result : value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_attribute_without_callbacks!(attribute_name, value)
|
56
|
+
without_callbacks do
|
57
|
+
write_attribute!(attribute_name, value)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def write_attribute!(attribute_name, value)
|
62
|
+
verify_not_hard_deleted!
|
63
|
+
|
64
|
+
with_changed_attribute_callbacks(attribute_name) do
|
65
|
+
load_if_necessary!(attribute_name)
|
66
|
+
|
67
|
+
attribute_name = attribute_name.to_sym
|
68
|
+
|
69
|
+
if attribute_name == primary_key_attribute && primary_key
|
70
|
+
outcome = cast_attribute(attribute_name, value)
|
71
|
+
|
72
|
+
if outcome.success?
|
73
|
+
value = outcome.result
|
74
|
+
end
|
75
|
+
|
76
|
+
if value != primary_key
|
77
|
+
raise UnexpectedPrimaryKeyChangeError,
|
78
|
+
"Primary key already set to #{primary_key}. Can't change to #{value}. " \
|
79
|
+
"Use attributes[:#{attribute_name}] = #{value.inspect} " \
|
80
|
+
"instead if you really want to change the primary key."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
attribute_name = attribute_name.to_sym
|
85
|
+
attributes[attribute_name] = cast_attribute!(attribute_name, value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def write_attributes_without_callbacks(attributes)
|
90
|
+
without_callbacks do
|
91
|
+
write_attributes(attributes)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_attributes(attributes)
|
96
|
+
verify_not_hard_deleted!
|
97
|
+
|
98
|
+
with_changed_attribute_callbacks(attributes.keys) do
|
99
|
+
load_if_necessary!(attributes)
|
100
|
+
|
101
|
+
attributes.each_pair do |attribute_name, value|
|
102
|
+
write_attribute_without_callbacks(attribute_name, value)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def read_attribute(attribute_name)
|
108
|
+
load_if_necessary!(attribute_name)
|
109
|
+
super
|
110
|
+
end
|
111
|
+
|
112
|
+
def read_attribute!(attribute_name)
|
113
|
+
load_if_necessary!(attribute_name)
|
114
|
+
super
|
115
|
+
end
|
116
|
+
|
117
|
+
def with_changed_attribute_callbacks(attribute_names)
|
118
|
+
# TODO: clean up methods to use this flag instead of calling each other
|
119
|
+
if @callbacks_disabled
|
120
|
+
yield
|
121
|
+
return
|
122
|
+
end
|
123
|
+
|
124
|
+
attribute_names = Util.array(attribute_names)
|
125
|
+
|
126
|
+
old_is_dirty = dirty? # TODO: don't bother with this check unless there are relevant callbacks
|
127
|
+
old_is_valid = valid? # TODO: don't bother with this check unless there are relevant callbacks
|
128
|
+
|
129
|
+
old_values = attribute_names.map { |attribute_name| read_attribute(attribute_name) }
|
130
|
+
|
131
|
+
yield
|
132
|
+
|
133
|
+
new_values = attribute_names.map { |attribute_name| read_attribute(attribute_name) }
|
134
|
+
|
135
|
+
attribute_changed = false
|
136
|
+
|
137
|
+
old_values.each.with_index do |old_value, index|
|
138
|
+
new_value = new_values[index]
|
139
|
+
|
140
|
+
if new_value != old_value
|
141
|
+
attribute_changed = true
|
142
|
+
fire(:attribute_changed, attribute_name: attribute_names[index], old_value:, new_value:)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if attribute_changed
|
147
|
+
new_is_dirty = dirty?
|
148
|
+
|
149
|
+
if old_is_dirty != new_is_dirty
|
150
|
+
old_is_dirty ? fire(:undirtied) : fire(:dirtied)
|
151
|
+
end
|
152
|
+
|
153
|
+
new_is_valid = valid?
|
154
|
+
|
155
|
+
if old_is_valid != new_is_valid
|
156
|
+
# TODO: don't bother with this check unless there are relevant callbacks
|
157
|
+
new_is_valid ? fire(:uninvalidated) : fire(:invalidated)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def values_at(data_path)
|
163
|
+
data_path = DataPath.new(data_path) unless data_path.is_a?(DataPath)
|
164
|
+
|
165
|
+
data_path.values_at(self)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Callbacks
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def reset_all
|
9
|
+
Entity.instance_variable_set("@class_callback_registry", nil)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# owner helps with determining the relevant object when running class-registered state transition callbacks
|
14
|
+
attr_accessor :callback_registry
|
15
|
+
|
16
|
+
def initialize(...)
|
17
|
+
self.callback_registry = Callback::Registry::ChainedMultipleAction.new(self.class.class_callback_registry)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: support passing multiple actions here
|
22
|
+
def fire(action, data = {})
|
23
|
+
callback_registry.runner(action).callback_data(data.merge(record: self, action:)).run
|
24
|
+
end
|
25
|
+
|
26
|
+
def without_callbacks
|
27
|
+
old_callbacks_enabled = @callbacks_disabled
|
28
|
+
|
29
|
+
begin
|
30
|
+
@callbacks_disabled = true
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
@callbacks_disabled = old_callbacks_enabled
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
foobara_delegate :register_callback, to: :callback_registry
|
38
|
+
|
39
|
+
module ClassMethods
|
40
|
+
def class_callback_registry
|
41
|
+
@class_callback_registry ||= begin
|
42
|
+
actions = %i[
|
43
|
+
initialized
|
44
|
+
initialized_built
|
45
|
+
initialized_thunk
|
46
|
+
initialized_loaded
|
47
|
+
initialized_created
|
48
|
+
dirtied
|
49
|
+
undirtied
|
50
|
+
attribute_changed
|
51
|
+
reverted
|
52
|
+
loaded
|
53
|
+
persisted
|
54
|
+
hard_deleted
|
55
|
+
unhard_deleted
|
56
|
+
invalidated
|
57
|
+
uninvalidated
|
58
|
+
]
|
59
|
+
|
60
|
+
if self == Entity
|
61
|
+
Callback::Registry::MultipleAction.new(actions).tap do |registry|
|
62
|
+
registry.allowed_types = [:after]
|
63
|
+
end
|
64
|
+
else
|
65
|
+
Callback::Registry::ChainedMultipleAction.new(superclass.class_callback_registry)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
foobara_delegate :register_callback, :possible_actions, to: :class_callback_registry
|
71
|
+
end
|
72
|
+
|
73
|
+
on_include do
|
74
|
+
class_callback_registry.allowed_types.each do |type|
|
75
|
+
[self, singleton_class].each do |target|
|
76
|
+
method_name = "#{type}_any_action"
|
77
|
+
|
78
|
+
target.define_method method_name do |&block|
|
79
|
+
register_callback(type, nil, &block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
possible_actions.each do |action|
|
84
|
+
method_name = "#{type}_#{action}"
|
85
|
+
|
86
|
+
[self, singleton_class].each do |target|
|
87
|
+
target.define_method method_name do |&block|
|
88
|
+
register_callback(type, action, &block)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
class NoCurrentTransactionError < StandardError; end
|
4
|
+
|
5
|
+
module Concerns
|
6
|
+
module Initialization
|
7
|
+
include Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def can_be_created_through_casting?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(attributes)
|
15
|
+
record = __private_new__
|
16
|
+
record.build(attributes)
|
17
|
+
# TODO: rename to something like "detached"
|
18
|
+
record.is_built = true
|
19
|
+
|
20
|
+
record.fire(:initialized)
|
21
|
+
record.fire(:initialized_built)
|
22
|
+
|
23
|
+
record
|
24
|
+
end
|
25
|
+
|
26
|
+
def thunk(record_id)
|
27
|
+
record_id = primary_key_type.process_value!(record_id)
|
28
|
+
|
29
|
+
# TODO: is this possible?
|
30
|
+
if record_id.nil?
|
31
|
+
# :nocov:
|
32
|
+
raise ArgumentError, "Primary key cannot be blank"
|
33
|
+
# :nocov:
|
34
|
+
end
|
35
|
+
|
36
|
+
# check if tracked already...
|
37
|
+
record = current_transaction_table.find_tracked(record_id)
|
38
|
+
|
39
|
+
return record if record
|
40
|
+
|
41
|
+
record = __private_new__
|
42
|
+
record.is_persisted = true
|
43
|
+
record.write_attributes_without_callbacks(primary_key_attribute => record_id)
|
44
|
+
|
45
|
+
record.fire(:initialized)
|
46
|
+
record.fire(:initialized_thunk)
|
47
|
+
|
48
|
+
record
|
49
|
+
end
|
50
|
+
|
51
|
+
def loaded(attributes)
|
52
|
+
attributes = attributes_type.process_value!(attributes)
|
53
|
+
|
54
|
+
record_id = attributes[primary_key_attribute]
|
55
|
+
|
56
|
+
record = current_transaction_table.find_tracked(record_id)
|
57
|
+
|
58
|
+
if record
|
59
|
+
# :nocov:
|
60
|
+
raise "Already loaded for #{attributes}. Bug maybe?"
|
61
|
+
# :nocov:
|
62
|
+
end
|
63
|
+
|
64
|
+
record = __private_new__
|
65
|
+
|
66
|
+
record.successfully_loaded(attributes)
|
67
|
+
|
68
|
+
unless record.primary_key
|
69
|
+
# :nocov:
|
70
|
+
raise "Expected primary key #{primary_key_attribute} to be present!"
|
71
|
+
# :nocov:
|
72
|
+
end
|
73
|
+
|
74
|
+
record.fire(:initialized)
|
75
|
+
record.fire(:initialized_loaded)
|
76
|
+
|
77
|
+
record
|
78
|
+
end
|
79
|
+
|
80
|
+
def create(attributes = {})
|
81
|
+
record = __private_new__
|
82
|
+
record.is_created = true
|
83
|
+
|
84
|
+
defaults = attributes_type.declaration_data[:defaults]
|
85
|
+
if defaults && !defaults.empty?
|
86
|
+
record.write_attributes_without_callbacks(defaults)
|
87
|
+
end
|
88
|
+
|
89
|
+
record.write_attributes_without_callbacks(attributes)
|
90
|
+
|
91
|
+
# TODO: delete :initialized if unused
|
92
|
+
record.fire(:initialized)
|
93
|
+
record.fire(:initialized_created)
|
94
|
+
|
95
|
+
record
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def successfully_loaded(attributes)
|
100
|
+
if hard_deleted?
|
101
|
+
# :nocov:
|
102
|
+
raise "Not expecting to load a hard deleted record"
|
103
|
+
# :nocov:
|
104
|
+
end
|
105
|
+
|
106
|
+
# TODO: why would we proceed if this is the case? Maybe raise?
|
107
|
+
already_loaded = loaded?
|
108
|
+
|
109
|
+
self.is_persisted = true
|
110
|
+
self.is_loaded = true
|
111
|
+
|
112
|
+
write_attributes_without_callbacks(attributes)
|
113
|
+
|
114
|
+
save_persisted_attributes
|
115
|
+
|
116
|
+
unless already_loaded
|
117
|
+
fire(:loaded)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def build(attributes = {})
|
122
|
+
write_attributes_without_callbacks(attributes)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Persistence
|
5
|
+
class CannotUpdateHardDeletedRecordError < StandardError; end
|
6
|
+
class UnknownIfPersisted < StandardError; end
|
7
|
+
|
8
|
+
include Concern
|
9
|
+
|
10
|
+
attr_accessor :is_loaded, :is_persisted, :is_hard_deleted, :is_built, :is_created, :persisted_attributes
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def entity_base
|
14
|
+
@entity_base ||= Foobara::Persistence.base_for_entity_class_name(full_entity_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def hard_delete!
|
19
|
+
hard_delete_without_callbacks!
|
20
|
+
fire(:hard_deleted)
|
21
|
+
end
|
22
|
+
|
23
|
+
def hard_delete_without_callbacks!
|
24
|
+
@is_hard_deleted = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_persisted_attributes
|
28
|
+
self.persisted_attributes = to_persisted_attributes(attributes)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_persisted_attributes(object)
|
32
|
+
case object
|
33
|
+
when ::Hash
|
34
|
+
object.to_h do |k, v|
|
35
|
+
[to_persisted_attributes(k), to_persisted_attributes(v)]
|
36
|
+
end
|
37
|
+
when ::Array
|
38
|
+
object.map { |v| to_persisted_attributes(v) }
|
39
|
+
else
|
40
|
+
object.dup
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Persisted means it is currently written to the database
|
45
|
+
def persisted?
|
46
|
+
is_persisted
|
47
|
+
end
|
48
|
+
|
49
|
+
def created?
|
50
|
+
is_created
|
51
|
+
end
|
52
|
+
|
53
|
+
def loaded?
|
54
|
+
is_loaded
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO: rename, maybe #detatched? or something?
|
58
|
+
def built?
|
59
|
+
is_built
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_if_necessary!(attribute_name_or_attributes)
|
63
|
+
return if built?
|
64
|
+
return if loaded?
|
65
|
+
return unless persisted?
|
66
|
+
|
67
|
+
attribute_name = if attribute_name_or_attributes.is_a?(::Hash)
|
68
|
+
if attribute_name_or_attributes.keys.size == 1
|
69
|
+
attribute_name_or_attributes.keys.first.to_sym
|
70
|
+
end
|
71
|
+
elsif attribute_name_or_attributes
|
72
|
+
attribute_name_or_attributes.to_sym
|
73
|
+
end
|
74
|
+
|
75
|
+
# TODO: are these symbols or not?
|
76
|
+
return if attribute_name == primary_key_attribute.to_sym
|
77
|
+
|
78
|
+
# TODO: how to get this out of here??
|
79
|
+
transaction = Foobara::Persistence::EntityBase::Transaction.open_transaction_for(self)
|
80
|
+
|
81
|
+
unless transaction
|
82
|
+
# :nocov:
|
83
|
+
raise NoCurrentTransactionError, "Trying to load a #{entity_name} outside of a transaction."
|
84
|
+
# :nocov:
|
85
|
+
end
|
86
|
+
|
87
|
+
unless transaction.loading?(self)
|
88
|
+
transaction.load(self)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def verify_not_hard_deleted!
|
93
|
+
if hard_deleted?
|
94
|
+
raise CannotUpdateHardDeletedRecordError,
|
95
|
+
"Cannot make further updates to this record because it has been hard deleted"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def unhard_delete!(skip_callbacks: false)
|
100
|
+
self.is_hard_deleted = false
|
101
|
+
|
102
|
+
unless skip_callbacks
|
103
|
+
fire(:unhard_deleted)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def restore!(skip_callbacks: false)
|
108
|
+
if persisted?
|
109
|
+
if hard_deleted?
|
110
|
+
unhard_delete!(skip_callbacks:)
|
111
|
+
end
|
112
|
+
|
113
|
+
if loaded?
|
114
|
+
if skip_callbacks
|
115
|
+
write_attributes_without_callbacks(persisted_attributes)
|
116
|
+
else
|
117
|
+
write_attributes(persisted_attributes)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
else
|
121
|
+
hard_delete!
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def restore_without_callbacks!
|
126
|
+
restore!(skip_callbacks: true)
|
127
|
+
end
|
128
|
+
|
129
|
+
def dirty?
|
130
|
+
return true unless persisted?
|
131
|
+
return false unless loaded?
|
132
|
+
|
133
|
+
persisted_attributes != to_persisted_attributes(attributes)
|
134
|
+
end
|
135
|
+
|
136
|
+
def hard_deleted?
|
137
|
+
@is_hard_deleted
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module PrimaryKey
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
foobara_delegate :primary_key_attribute, to: :class
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def primary_key(attribute_name)
|
11
|
+
if primary_key_attribute
|
12
|
+
# :nocov:
|
13
|
+
raise "Primary key already set to #{primary_key_attribute}"
|
14
|
+
# :nocov:
|
15
|
+
end
|
16
|
+
|
17
|
+
if attribute_name.nil? || attribute_name.empty?
|
18
|
+
# :nocov:
|
19
|
+
raise ArgumentError, "Primary key can't be blank"
|
20
|
+
# :nocov:
|
21
|
+
end
|
22
|
+
|
23
|
+
@primary_key_attribute = attribute_name.to_sym
|
24
|
+
|
25
|
+
set_model_type
|
26
|
+
end
|
27
|
+
|
28
|
+
def primary_key_attribute
|
29
|
+
return @primary_key_attribute if @primary_key_attribute
|
30
|
+
|
31
|
+
unless superclass == Entity
|
32
|
+
@primary_key_attribute = superclass.primary_key_attribute
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def primary_key
|
38
|
+
read_attribute(primary_key_attribute)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Entity < Model
|
3
|
+
module Concerns
|
4
|
+
module Queries
|
5
|
+
include Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def all(&)
|
9
|
+
current_transaction_table.all(&)
|
10
|
+
end
|
11
|
+
|
12
|
+
def first
|
13
|
+
# TODO: don't all queries need to do this???
|
14
|
+
Foobara::Namespace.use entity_type do
|
15
|
+
current_transaction_table.first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_by_attribute(attribute_name, value)
|
20
|
+
current_transaction_table.find_by_attribute(attribute_name, value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_all_by_attribute(attribute_name, value)
|
24
|
+
current_transaction_table.find_all_by_attribute(attribute_name, value)
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_by_attribute_containing(attribute_name, value)
|
28
|
+
current_transaction_table.find_by_attribute_containing(attribute_name, value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_all_by_attribute_containing_any_of(attribute_name, values)
|
32
|
+
current_transaction_table.find_all_by_attribute_containing_any_of(attribute_name, values)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_all_by_attribute_any_of(attribute_name, values)
|
36
|
+
current_transaction_table.find_all_by_attribute_any_of(attribute_name, values)
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_by(attributes)
|
40
|
+
current_transaction_table.find_by(attributes)
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_many_by(attributes)
|
44
|
+
current_transaction_table.find_many_by(attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
def load(record)
|
48
|
+
if !record.is_a?(Foobara::Entity) || !record.loaded?
|
49
|
+
current_transaction_table.load(record)
|
50
|
+
end
|
51
|
+
rescue ::Foobara::Persistence::EntityAttributesCrudDriver::Table::CannotFindError
|
52
|
+
primary_key = if record.is_a?(Foobara::Entity)
|
53
|
+
record.primary_key
|
54
|
+
else
|
55
|
+
record
|
56
|
+
end
|
57
|
+
|
58
|
+
raise NotFoundError.new(primary_key, entity_class: self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_aggregate(record_or_record_id)
|
62
|
+
record = if record_or_record_id.is_a?(Entity)
|
63
|
+
record_or_record_id
|
64
|
+
else
|
65
|
+
thunk(record_or_record_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
current_transaction.load_aggregate(record)
|
69
|
+
end
|
70
|
+
|
71
|
+
def load_many(*record_ids)
|
72
|
+
if record_ids.size == 1 && record_ids.first.is_a?(::Array)
|
73
|
+
record_ids = record_ids.first
|
74
|
+
end
|
75
|
+
|
76
|
+
current_transaction_table.load_many(record_ids)
|
77
|
+
end
|
78
|
+
|
79
|
+
def all_exist?(record_ids)
|
80
|
+
# TODO: support splat
|
81
|
+
current_transaction_table.all_exist?(record_ids)
|
82
|
+
end
|
83
|
+
|
84
|
+
def exists?(record_id)
|
85
|
+
# TODO: support splat
|
86
|
+
current_transaction_table.exists?(record_id)
|
87
|
+
end
|
88
|
+
|
89
|
+
def count
|
90
|
+
current_transaction_table.count
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|