foobara 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,24 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
|
8
|
+
class TypeDesugarizer < TypeDeclarations::Desugarizer
|
|
9
|
+
def applicable?(sugary_type_declaration)
|
|
10
|
+
sugary_type_declaration.is_a?(Types::Type)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def desugarize(type)
|
|
14
|
+
type.reference_or_declaration_data
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def priority
|
|
18
|
+
Priority::FIRST - 1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "type_declaration_handler")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
# TODO: we should just use the symbol instead of {type: symbol} to save space and simplify some stuff...
|
|
7
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
8
|
+
def applicable?(sugary_type_declaration)
|
|
9
|
+
strict_type_declaration = desugarize(sugary_type_declaration)
|
|
10
|
+
|
|
11
|
+
return false unless strict_type_declaration.is_a?(::Hash)
|
|
12
|
+
|
|
13
|
+
# we only handle case where it's a builtin type not an extension of one
|
|
14
|
+
if strict_type_declaration.keys == [:type]
|
|
15
|
+
type_symbol = strict_type_declaration[:type]
|
|
16
|
+
type_registered?(type_symbol)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def priority
|
|
21
|
+
Priority::HIGH
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
class TypeBuilder
|
|
4
|
+
class NoTypeDeclarationHandlerFoundError < StandardError; end
|
|
5
|
+
|
|
6
|
+
include TruncatedInspect
|
|
7
|
+
|
|
8
|
+
attr_accessor :name, :type_declaration_handler_registry, :accesses
|
|
9
|
+
|
|
10
|
+
def initialize(
|
|
11
|
+
name,
|
|
12
|
+
accesses: GlobalDomain.foobara_type_builder,
|
|
13
|
+
type_declaration_handler_registry: TypeDeclarations::TypeDeclarationHandlerRegistry.new
|
|
14
|
+
)
|
|
15
|
+
self.name = name
|
|
16
|
+
self.type_declaration_handler_registry = type_declaration_handler_registry
|
|
17
|
+
self.accesses = Util.array(accesses).to_set
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def accesses_up_hierarchy
|
|
21
|
+
[self, *accesses, *accesses.map(&:accesses_up_hierarchy).flatten].uniq
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# declaration handlers
|
|
25
|
+
|
|
26
|
+
def register_type_declaration_handler(type_declaration_handler)
|
|
27
|
+
type_declaration_handler_registry.register(type_declaration_handler)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def type_declaration_handler_registries
|
|
31
|
+
accesses_up_hierarchy.map(&:type_declaration_handler_registry)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def type_declaration_handler_for(type_declaration)
|
|
35
|
+
handlers.each do |handler|
|
|
36
|
+
return handler if handler.applicable?(type_declaration)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
raise NoTypeDeclarationHandlerFoundError,
|
|
40
|
+
"No type declaration handler found for #{type_declaration}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def handlers
|
|
44
|
+
type_declaration_handler_registries.map(&:handlers).flatten.sort_by(&:priority)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def handler_for_class(klass)
|
|
48
|
+
handlers.find { |handler| handler.instance_of?(klass) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def type_for_strict_stringified_declaration(type_declaration)
|
|
52
|
+
TypeDeclarations.strict_stringified do
|
|
53
|
+
handler = type_declaration_handler_for(type_declaration)
|
|
54
|
+
handler.process_value!(type_declaration)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def type_for_strict_declaration(type_declaration)
|
|
59
|
+
TypeDeclarations.strict do
|
|
60
|
+
handler = type_declaration_handler_for(type_declaration)
|
|
61
|
+
handler.process_value!(type_declaration)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def type_for_declaration(*type_declaration_bits, &block)
|
|
66
|
+
type_declaration = if block
|
|
67
|
+
unless type_declaration_bits.empty?
|
|
68
|
+
# :nocov:
|
|
69
|
+
raise ArgumentError, "Cannot provide both block and declaration"
|
|
70
|
+
# :nocov:
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
block
|
|
74
|
+
else
|
|
75
|
+
case type_declaration_bits.size
|
|
76
|
+
when 0
|
|
77
|
+
# :nocov:
|
|
78
|
+
raise ArgumentError, "expected 1 argument or a block but got 0 arguments and no block"
|
|
79
|
+
# :nocov:
|
|
80
|
+
when 1
|
|
81
|
+
type_declaration_bits.first
|
|
82
|
+
else
|
|
83
|
+
type_declaration_bits_to_type_declaration(type_declaration_bits)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
handler = type_declaration_handler_for(type_declaration)
|
|
88
|
+
handler.process_value!(type_declaration)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def type_declaration_bits_to_type_declaration(type_declaration_bits)
|
|
94
|
+
type, *symbolic_processors, processor_data = type_declaration_bits
|
|
95
|
+
|
|
96
|
+
if !symbolic_processors.empty?
|
|
97
|
+
symbolic_processors = symbolic_processors.to_h { |symbol| [symbol, true] }
|
|
98
|
+
|
|
99
|
+
if processor_data.is_a?(::Hash) && !processor_data.empty?
|
|
100
|
+
processor_data.merge(symbolic_processors)
|
|
101
|
+
else
|
|
102
|
+
symbolic_processors
|
|
103
|
+
end
|
|
104
|
+
elsif processor_data.is_a?(::Hash)
|
|
105
|
+
processor_data
|
|
106
|
+
else
|
|
107
|
+
{ processor_data.to_sym => true }
|
|
108
|
+
end.merge(type:)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "with_registries")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
class TypeDeclarationHandler < Value::Processor::Pipeline
|
|
6
|
+
class << self
|
|
7
|
+
def foobara_manifest(to_include:)
|
|
8
|
+
# :nocov:
|
|
9
|
+
super.merge(processor_type: :type_declaration_handler)
|
|
10
|
+
# :nocov:
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def starting_desugarizers
|
|
14
|
+
starting_desugarizers_with_inherited
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def starting_desugarizers_with_inherited
|
|
18
|
+
# TODO: this is not great because if new stuff gets registered at runtime then we can't really
|
|
19
|
+
# update this cached data easily
|
|
20
|
+
if superclass == TypeDeclarationHandler
|
|
21
|
+
starting_desugarizers_without_inherited
|
|
22
|
+
else
|
|
23
|
+
[*superclass.starting_desugarizers, *starting_desugarizers_without_inherited]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def starting_desugarizers_without_inherited
|
|
28
|
+
# TODO: this is not great because if new stuff gets registered at runtime then we can't really
|
|
29
|
+
# update this cached data easily
|
|
30
|
+
Util.constant_values(self, extends: TypeDeclarations::Desugarizer).map(&:instance)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def starting_type_declaration_validators
|
|
34
|
+
# TODO: this is not great because if new stuff gets registered at runtime then we can't really
|
|
35
|
+
# update this cached data easily
|
|
36
|
+
Util.constant_values(self, extends: Value::Validator, inherit: true).map(&:instance)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
include WithRegistries
|
|
41
|
+
|
|
42
|
+
attr_accessor :desugarizers, :type_declaration_validators
|
|
43
|
+
|
|
44
|
+
def initialize(
|
|
45
|
+
*args,
|
|
46
|
+
processors: nil,
|
|
47
|
+
desugarizers: starting_desugarizers,
|
|
48
|
+
type_declaration_validators: starting_type_declaration_validators,
|
|
49
|
+
**opts
|
|
50
|
+
)
|
|
51
|
+
if processors && !processors.empty?
|
|
52
|
+
# :nocov:
|
|
53
|
+
raise ArgumentError, "Cannot set processors directly for a type declaration handler"
|
|
54
|
+
# :nocov:
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
self.desugarizers = Util.array(desugarizers)
|
|
58
|
+
self.type_declaration_validators = Util.array(type_declaration_validators)
|
|
59
|
+
|
|
60
|
+
super(*Util.args_and_opts_to_args(args, opts))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
foobara_delegate :starting_desugarizers,
|
|
64
|
+
:starting_desugarizers_with_inherited,
|
|
65
|
+
:starting_desugarizers_without_inherited,
|
|
66
|
+
:starting_type_declaration_validators,
|
|
67
|
+
to: :class
|
|
68
|
+
|
|
69
|
+
def to_type_transformer
|
|
70
|
+
self.class::ToTypeTransformer.instance
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def inspect
|
|
74
|
+
# :nocov:
|
|
75
|
+
s = super
|
|
76
|
+
|
|
77
|
+
if s.size > 400
|
|
78
|
+
s = "#{s[0..400]}..."
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
s
|
|
82
|
+
# :nocov:
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def applicable?(_sugary_type_declaration)
|
|
86
|
+
# :nocov:
|
|
87
|
+
raise "subclass responsibility"
|
|
88
|
+
# :nocov:
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def processors
|
|
92
|
+
[desugarizer, type_declaration_validator, to_type_transformer]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def process_value(raw_type_declaration)
|
|
96
|
+
# TODO: deep_dup this again??
|
|
97
|
+
super(raw_type_declaration).tap do |type_outcome|
|
|
98
|
+
if type_outcome.success?
|
|
99
|
+
type_outcome.result.raw_declaration_data = raw_type_declaration
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def desugarizer
|
|
105
|
+
# TODO: memoize this?
|
|
106
|
+
Value::Processor::Pipeline.new(processors: desugarizers)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def desugarize(value)
|
|
110
|
+
desugarizer.process_value!(value)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def type_declaration_validator
|
|
114
|
+
Value::Processor::Pipeline.new(processors: type_declaration_validators)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
alias to_type process_value!
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
class TypeDeclarationHandlerRegistry < Value::Processor::Selection
|
|
4
|
+
class << self
|
|
5
|
+
def foobara_manifest(to_include:)
|
|
6
|
+
# :nocov:
|
|
7
|
+
super.merge(processor_type: :type_declaration_handler_registry)
|
|
8
|
+
# :nocov:
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
super(enforce_unique: false)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def type_declaration_handler_for_handler_class(type_declaration_handler_class)
|
|
17
|
+
processors.find do |type_declaration_handler|
|
|
18
|
+
type_declaration_handler.instance_of?(type_declaration_handler_class)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
alias type_declaration_handler_for processor_for!
|
|
23
|
+
alias handlers processors
|
|
24
|
+
alias type_for process_value!
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
class TypeDeclarationValidator < Value::Validator
|
|
4
|
+
include WithRegistries
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def foobara_manifest(to_include:)
|
|
8
|
+
# :nocov:
|
|
9
|
+
super.merge(processor_type: :type_declaration_validator)
|
|
10
|
+
# :nocov:
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def always_applicable?
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
require_project_file("type_declarations", "type_builder")
|
|
3
|
+
require_project_file("type_declarations", "error_extension")
|
|
4
|
+
|
|
5
|
+
module TypeDeclarations
|
|
6
|
+
module Mode
|
|
7
|
+
STRICT = :strict
|
|
8
|
+
STRICT_STRINGIFIED = :strict_stringified
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def global_type_declaration_handler_registry
|
|
13
|
+
GlobalDomain.foobara_type_builder.type_declaration_handler_registry
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def register_type_declaration(type_declaration_handler)
|
|
17
|
+
global_type_declaration_handler_registry.register(type_declaration_handler)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def strict(&)
|
|
21
|
+
using_mode(Mode::STRICT, &)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def strict_stringified(&)
|
|
25
|
+
using_mode(Mode::STRICT_STRINGIFIED, &)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def using_mode(new_mode)
|
|
29
|
+
old_mode = Thread.foobara_var_get(:foobara_type_declarations_mode)
|
|
30
|
+
begin
|
|
31
|
+
Thread.foobara_var_set(:foobara_type_declarations_mode, new_mode)
|
|
32
|
+
yield
|
|
33
|
+
ensure
|
|
34
|
+
Thread.foobara_var_set(:foobara_type_declarations_mode, old_mode)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def strict?
|
|
39
|
+
Thread.foobara_var_get(:foobara_type_declarations_mode) == Mode::STRICT
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def strict_stringified?
|
|
43
|
+
Thread.foobara_var_get(:foobara_type_declarations_mode) == Mode::STRICT_STRINGIFIED
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
=begin
|
|
50
|
+
how many handlers do we need??
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
find registered type by symbol
|
|
54
|
+
|
|
55
|
+
extend registered type (find it by symbol and use it to construct new type with additional processors)
|
|
56
|
+
|
|
57
|
+
Duck
|
|
58
|
+
AtomicDuck
|
|
59
|
+
Number
|
|
60
|
+
Integer
|
|
61
|
+
BigInteger
|
|
62
|
+
Float
|
|
63
|
+
BigDecimal
|
|
64
|
+
String
|
|
65
|
+
Email
|
|
66
|
+
Phone
|
|
67
|
+
Datetime
|
|
68
|
+
Date
|
|
69
|
+
Boolean
|
|
70
|
+
Duckture
|
|
71
|
+
Array
|
|
72
|
+
Tuple
|
|
73
|
+
AssociativeArray
|
|
74
|
+
Attributes
|
|
75
|
+
Model
|
|
76
|
+
Address
|
|
77
|
+
UsAddress
|
|
78
|
+
Entity
|
|
79
|
+
|
|
80
|
+
Duck (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
81
|
+
AtomicDuck (N/A)
|
|
82
|
+
Number (N/A)
|
|
83
|
+
Integer (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
84
|
+
BigInteger (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
85
|
+
Float (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
86
|
+
BigDecimal (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
87
|
+
String (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
88
|
+
Email (implement in terms of string extension)
|
|
89
|
+
Phone (implement in terms of string extension)
|
|
90
|
+
Datetime (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
91
|
+
Date (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
92
|
+
Boolean (RegisteredTypeExtensionTypeDeclarationHandler)
|
|
93
|
+
Duckture (N/A)
|
|
94
|
+
Array (hmmmm we need an element processor initialized with the element type...)
|
|
95
|
+
Tuple (hmmmm we need an element processor initialized with the elements type...)
|
|
96
|
+
AssociativeArray (hmmmm we need an element processor initialized with the key type and the value type...)
|
|
97
|
+
Attributes (we need an element processor initialized with the attribute_types)
|
|
98
|
+
Model (same as above but need to add a name attribute...)
|
|
99
|
+
Address (implement in terms of model)
|
|
100
|
+
UsAddress (implement in terms of Address)
|
|
101
|
+
Entity (same as above but with a primary key processor of some sort)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
TypeDeclarationHandler
|
|
105
|
+
RegisteredAtomTypeExtensionTypeDeclarationHandler
|
|
106
|
+
RegisteredStructuredTypeExtensionTypeDeclarationHandler
|
|
107
|
+
ExtendArrayTypeDeclarationHandler
|
|
108
|
+
ExtendTupleTypeDeclarationHandler
|
|
109
|
+
ExtendAssociativeArrayTypeDeclaration
|
|
110
|
+
ExtendAttributesTypeDeclaration
|
|
111
|
+
ExtendModelTypeDeclarationHandler
|
|
112
|
+
ExtendEntityTypeDeclarationHandler
|
|
113
|
+
|
|
114
|
+
I think we need these type declarations but not necessarily Type subclasses for all of these types
|
|
115
|
+
|
|
116
|
+
Maybe just one Type class??
|
|
117
|
+
|
|
118
|
+
let's see...
|
|
119
|
+
|
|
120
|
+
for atom could just not support element_types nor size
|
|
121
|
+
for array element_types could just be applied repeating?? Kind of goofy
|
|
122
|
+
For tuple element_types could be applied repeating and size validator could be added
|
|
123
|
+
for associative array... element_types need to be a hash instead of an array. Is that OK?
|
|
124
|
+
Or could be an array of pairs... like Hash#to_a ? Maybe we just operate off of #each? Seems that will work, wow...
|
|
125
|
+
For Attributes same as associative array but with key processor of symbol plus an attributes_processor
|
|
126
|
+
For model add a name processor
|
|
127
|
+
for entity add a primary key processor of some sort...
|
|
128
|
+
=end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
# TODO: this should instead be a processor and have its own possible_errors
|
|
4
|
+
class TypedTransformer < Value::Transformer
|
|
5
|
+
class << self
|
|
6
|
+
# A,B,C,D
|
|
7
|
+
# let's say this transformer is C...
|
|
8
|
+
# If we are a noop, then we are going to output D.type and we expect B.type
|
|
9
|
+
# We obviously have a problem if D is incompatible with our output type.
|
|
10
|
+
# We need to know B.output_type in order to say what we are going to output.
|
|
11
|
+
#
|
|
12
|
+
# Conversely, we need to know what D expects in order to say what we expect to receive (sometimes)
|
|
13
|
+
#
|
|
14
|
+
# So logic is... For C to say what its type is, it must know B's output_type.
|
|
15
|
+
# or... I guess for an inputs transformer, we need to know what D expects as its type, right?
|
|
16
|
+
# since we have an obligation be compatible with it.
|
|
17
|
+
#
|
|
18
|
+
# Use case 1: command line interface gets awkward with models
|
|
19
|
+
# 1. Command takes model A
|
|
20
|
+
# 2. we want an inputs transformer that takes A.attributes_type
|
|
21
|
+
# 3. Therefore its type is A.attributes_type
|
|
22
|
+
# 4. And also, its output type is A.attributes_type in this case since there's no need to actually create the
|
|
23
|
+
# models.
|
|
24
|
+
# 5. So to tell our type, we must know the type of what comes next.
|
|
25
|
+
#
|
|
26
|
+
# Use case 2:
|
|
27
|
+
# 1. Command takes foo: :integer but we want to take bar: :string
|
|
28
|
+
# 2. transformer has this hard-coded knowledge.
|
|
29
|
+
# 3. we don't need to receive either types to answer our input and output types.
|
|
30
|
+
#
|
|
31
|
+
# Use case 3: Changing a record into its primary key
|
|
32
|
+
# 1. Command has result type of A which is an Entity
|
|
33
|
+
# 2. transformer takes an A record and returns record.primary_key
|
|
34
|
+
# 3. To know the output type, we need to know the result type of the previous type.
|
|
35
|
+
# 4. To know the input type, we need to know the type of the previous transformer since they are the same.
|
|
36
|
+
# (however, by convention we can just use nil in this case.)
|
|
37
|
+
#
|
|
38
|
+
# Use case 4: document upload
|
|
39
|
+
# 1. Command takes input stream plus some document info
|
|
40
|
+
# 2. controller action receives temporary file path
|
|
41
|
+
# 3. transformer opens input stream and replaces file path with input stream
|
|
42
|
+
# 4. In this case, we have hard-coded types.
|
|
43
|
+
#
|
|
44
|
+
# Challenge: we seem to not know in advance if the transformer needs to know what comes before it or what comes
|
|
45
|
+
# after it. Unless we are writing a one-off transformer then we have hard-coded knowledge.
|
|
46
|
+
#
|
|
47
|
+
# Seems like input transformer really needs to know what comes next, the target type.
|
|
48
|
+
# Seems like output transformer might require to know what came previously
|
|
49
|
+
#
|
|
50
|
+
# Plan:
|
|
51
|
+
# 1. Both inputs transformer and result have similar structure... they have a relevant type that they transform.
|
|
52
|
+
# The difference is that the result takes previous steps output and transforms it to a different type, whereas
|
|
53
|
+
# the input transformer needs to know what comes next in order to communicate its types.
|
|
54
|
+
# So we might be able to get away with a transformed_type that accepts the from_type. And the calling code can
|
|
55
|
+
# interpret how it goes. This might create some awkwardness or confusion at least when creating one of the
|
|
56
|
+
# two types of transformer.
|
|
57
|
+
def type_declaration(_from_type)
|
|
58
|
+
nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def type(from_type)
|
|
62
|
+
dec = type_declaration(from_type)
|
|
63
|
+
|
|
64
|
+
if dec
|
|
65
|
+
if dec.is_a?(Types::Type)
|
|
66
|
+
dec
|
|
67
|
+
else
|
|
68
|
+
Domain.current.foobara_type_from_declaration(dec)
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
alias from_type declaration_data
|
|
76
|
+
|
|
77
|
+
def type
|
|
78
|
+
return @type if @type
|
|
79
|
+
|
|
80
|
+
@type = self.class.type(from_type)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def process_value(value)
|
|
84
|
+
output = transform(value)
|
|
85
|
+
Outcome.success(output)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
module WithRegistries
|
|
4
|
+
include Concern
|
|
5
|
+
|
|
6
|
+
module ClassMethods
|
|
7
|
+
def type_for_declaration(...)
|
|
8
|
+
Domain.current.foobara_type_from_declaration(...)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def type_declaration_handler_for(...)
|
|
12
|
+
Domain.current.foobara_type_builder.type_declaration_handler_for(...)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def lookup_absolute_type!(*, **opts, &)
|
|
16
|
+
Foobara::Namespace.global.foobara_lookup_type!(*, **opts.merge(mode: Namespace::LookupMode::ABSOLUTE), &)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def lookup_type!(...)
|
|
20
|
+
Foobara::Namespace.current.foobara_lookup_type!(...)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def type_registered?(...)
|
|
24
|
+
Foobara::Namespace.current.foobara_type_registered?(...)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def handler_for_class(...)
|
|
28
|
+
Domain.current.foobara_type_builder.handler_for_class(...)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
foobara_delegate :type_for_declaration,
|
|
33
|
+
:type_declaration_handler_for,
|
|
34
|
+
:lookup_type!,
|
|
35
|
+
:lookup_absolute_type!,
|
|
36
|
+
:type_registered?,
|
|
37
|
+
:handler_for_class,
|
|
38
|
+
to: :class
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|