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,123 @@
|
|
1
|
+
Foobara.require_project_file("value", "data_error")
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Value
|
5
|
+
class Processor
|
6
|
+
# TODO: at least move this up to Types though that doesn't solve the issue
|
7
|
+
class Casting < Selection
|
8
|
+
class CannotCastError < DataError
|
9
|
+
class << self
|
10
|
+
def fatal?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
if path.empty?
|
17
|
+
super
|
18
|
+
else
|
19
|
+
"At #{path.join(".")}: #{super}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def foobara_manifest(to_include:)
|
26
|
+
# :nocov:
|
27
|
+
super.merge(processor_type: :casting)
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
|
31
|
+
def error_classes
|
32
|
+
[CannotCastError]
|
33
|
+
end
|
34
|
+
|
35
|
+
def requires_declaration_data?
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_accessor :target_classes
|
41
|
+
|
42
|
+
def initialize(*args, casters:, target_classes: nil)
|
43
|
+
self.target_classes = Util.array(target_classes)
|
44
|
+
|
45
|
+
processors = [
|
46
|
+
*does_not_need_cast_processor,
|
47
|
+
*casters
|
48
|
+
]
|
49
|
+
|
50
|
+
super(*args, processors:)
|
51
|
+
end
|
52
|
+
|
53
|
+
def needs_cast?(value)
|
54
|
+
!does_not_need_cast_processor.applicable?(value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def can_cast?(value)
|
58
|
+
processors.any? { |processor| processor.applicable?(value) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def does_not_need_cast_processor
|
62
|
+
return @does_not_need_cast_processor if defined?(@does_not_need_cast_processor)
|
63
|
+
|
64
|
+
class_name = "NoCastNeededIfIsA#{target_classes.map { |c| c.name.gsub("::", "") }.sort.join("Or")}"
|
65
|
+
|
66
|
+
@does_not_need_cast_processor = if target_classes && !target_classes.empty?
|
67
|
+
Caster.subclass(
|
68
|
+
name: class_name,
|
69
|
+
applicable?: ->(value) {
|
70
|
+
target_classes.any? { |target_class| value.is_a?(target_class) }
|
71
|
+
},
|
72
|
+
applies_message: "be a #{target_classes.map(&:name).join(" or ")}",
|
73
|
+
cast: ->(value) { value }
|
74
|
+
).instance
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def error_message(value)
|
79
|
+
type = declaration_data[:cast_to][:type].to_s
|
80
|
+
article = type =~ /^[aeiouy]/i ? "an" : "a"
|
81
|
+
|
82
|
+
"Cannot cast #{value.inspect} to #{article} #{type}. Expected it to #{applies_message}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def applies_message
|
86
|
+
Util.to_or_sentence(processors.map(&:applies_message).flatten)
|
87
|
+
end
|
88
|
+
|
89
|
+
def error_context(value)
|
90
|
+
{
|
91
|
+
cast_to:,
|
92
|
+
value:
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def build_error(*args, **opts)
|
97
|
+
error_class = opts[:error_class]
|
98
|
+
|
99
|
+
if error_class == NoApplicableProcessorError
|
100
|
+
build_error(*args)
|
101
|
+
elsif error_class == MoreThanOneApplicableProcessorError
|
102
|
+
# :nocov:
|
103
|
+
raise "Matched too many casters for #{args.inspect} with #{opts.inspect}"
|
104
|
+
# :nocov:
|
105
|
+
else
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def cast_to
|
111
|
+
# TODO: isn't there a way to declare declaration_data_type so we don't have to validate here??
|
112
|
+
unless declaration_data.key?(:cast_to)
|
113
|
+
# :nocov:
|
114
|
+
raise "Missing cast_to"
|
115
|
+
# :nocov:
|
116
|
+
end
|
117
|
+
|
118
|
+
declaration_data[:cast_to]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Value
|
3
|
+
class Processor
|
4
|
+
class Multi < Processor
|
5
|
+
attr_accessor :processors, :prioritize
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def requires_declaration_data?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(*args, processors: [], prioritize: true)
|
14
|
+
self.prioritize = prioritize
|
15
|
+
self.processors = prioritize ? processors.sort_by(&:priority) : processors
|
16
|
+
super(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def processor_names
|
20
|
+
processors.map(&:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def error_classes
|
24
|
+
normalize_error_classes([*super, *processors.map(&:error_classes).flatten])
|
25
|
+
end
|
26
|
+
|
27
|
+
def applicable?(value)
|
28
|
+
super || processors.any? { |processor| processor.applicable?(value) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def possible_errors
|
32
|
+
return @possible_errors if @possible_errors
|
33
|
+
|
34
|
+
h = super.to_h do |possible_error|
|
35
|
+
[possible_error.key.to_s, possible_error]
|
36
|
+
end
|
37
|
+
|
38
|
+
processors.map(&:possible_errors).flatten.each do |possible_error|
|
39
|
+
h[possible_error.key.to_s] = possible_error
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: change this back to a hash
|
43
|
+
@possible_errors = h.values
|
44
|
+
end
|
45
|
+
|
46
|
+
def register(processor)
|
47
|
+
self.processors = [*processors, processor].sort_by(&:priority)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def normalize_error_classes(error_classes)
|
53
|
+
cannot_cast_errors, others = error_classes.partition do |c|
|
54
|
+
# TODO: some kind of dependency issue here??
|
55
|
+
c == Foobara::Value::Processor::Casting::CannotCastError
|
56
|
+
end
|
57
|
+
|
58
|
+
[*cannot_cast_errors.uniq, *others]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Foobara.require_project_file("value", "processor/multi")
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Value
|
5
|
+
class Processor
|
6
|
+
class Pipeline < Multi
|
7
|
+
class << self
|
8
|
+
def foobara_manifest(to_include:)
|
9
|
+
# :nocov:
|
10
|
+
super.merge(processor_type: :pipeline)
|
11
|
+
# :nocov:
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def process_outcome(old_outcome)
|
16
|
+
processors.inject(old_outcome) do |outcome, processor|
|
17
|
+
processor.process_outcome(outcome)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_value(value)
|
22
|
+
process_outcome(Outcome.success(value))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Value
|
3
|
+
class Processor
|
4
|
+
class Runner
|
5
|
+
class << self
|
6
|
+
def runner_methods(*method_names)
|
7
|
+
method_names.each do |method_name|
|
8
|
+
instance_variable = :"@#{method_name}"
|
9
|
+
|
10
|
+
define_method method_name do
|
11
|
+
if instance_variables.include?(instance_variable)
|
12
|
+
instance_variable_get(instance_variable)
|
13
|
+
else
|
14
|
+
instance_variable_set(instance_variable, processor.send(method_name, value))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :value, :processor
|
22
|
+
|
23
|
+
def initialize(processor, value)
|
24
|
+
self.processor = processor
|
25
|
+
self.value = value
|
26
|
+
end
|
27
|
+
|
28
|
+
runner_methods :error_message,
|
29
|
+
:error_context,
|
30
|
+
:process_value,
|
31
|
+
:process_value!,
|
32
|
+
:process_outcome,
|
33
|
+
:process_outcome!,
|
34
|
+
:applicable?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Foobara.require_project_file("value", "processor/multi")
|
2
|
+
Foobara.require_project_file("value", "data_error")
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module Value
|
6
|
+
class Processor
|
7
|
+
class Selection < Multi
|
8
|
+
class NoApplicableProcessorError < DataError; end
|
9
|
+
class MoreThanOneApplicableProcessorError < DataError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def foobara_manifest(to_include:)
|
13
|
+
# :nocov:
|
14
|
+
super.merge(processor_type: :selection)
|
15
|
+
# :nocov:
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :enforce_unique
|
20
|
+
|
21
|
+
def initialize(*args, enforce_unique: true, **opts)
|
22
|
+
self.enforce_unique = enforce_unique
|
23
|
+
super(*args, **opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
# TODO: move applies_message usage here from casting processor
|
27
|
+
def process_value(value)
|
28
|
+
outcome = processor_for(value)
|
29
|
+
|
30
|
+
if outcome.success?
|
31
|
+
processor = outcome.result
|
32
|
+
outcome = processor.process_value(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
outcome
|
36
|
+
end
|
37
|
+
|
38
|
+
def processor_for(value)
|
39
|
+
processor = if enforce_unique
|
40
|
+
applicable_processors = processors.select { |p| p.applicable?(value) }
|
41
|
+
|
42
|
+
if applicable_processors.size > 1
|
43
|
+
return Outcome.error(
|
44
|
+
build_error(
|
45
|
+
value,
|
46
|
+
error_class: MoreThanOneApplicableProcessorError,
|
47
|
+
message: "More than one processor applicable for #{value}",
|
48
|
+
context: error_context(value).merge(
|
49
|
+
applicable_processor_names: applicable_processors.map(&:name)
|
50
|
+
)
|
51
|
+
)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
applicable_processors.first
|
56
|
+
else
|
57
|
+
processors.find { |processor| processor.applicable?(value) }
|
58
|
+
end
|
59
|
+
|
60
|
+
if processor
|
61
|
+
Outcome.success(processor)
|
62
|
+
else
|
63
|
+
Outcome.error(build_error(value, error_class: NoApplicableProcessorError))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def processor_for!(value)
|
68
|
+
processor_for(value).result!
|
69
|
+
end
|
70
|
+
|
71
|
+
def always_applicable?
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def error_message(value)
|
76
|
+
# TODO: should override this message so we say registry or caster or whatever based on the situation
|
77
|
+
"Could not find processor that is applicable for #{value}"
|
78
|
+
end
|
79
|
+
|
80
|
+
# This is a problem... how do we know a base class won't call this for a different error??
|
81
|
+
def error_context(value)
|
82
|
+
{
|
83
|
+
processor_names:,
|
84
|
+
value:
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,358 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Value
|
3
|
+
class Processor
|
4
|
+
foobara_subclasses_are_namespaces!(default_parent: GlobalDomain, autoregister: true)
|
5
|
+
# Do we really need both to be namespaces??
|
6
|
+
foobara_instances_are_namespaces!(default_parent: GlobalDomain)
|
7
|
+
|
8
|
+
include Manifestable
|
9
|
+
include IsManifestable
|
10
|
+
|
11
|
+
module Priority
|
12
|
+
FIRST = 0
|
13
|
+
HIGH = 10
|
14
|
+
MEDIUM = 20
|
15
|
+
LOW = 30
|
16
|
+
LOWEST = 40
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def processor_name
|
21
|
+
name || "Anonymous"
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_declaration_data
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def foobara_manifest(to_include:)
|
29
|
+
errors = error_classes.map do |error_class|
|
30
|
+
to_include << error_class
|
31
|
+
error_class.foobara_manifest_reference
|
32
|
+
end
|
33
|
+
|
34
|
+
manifest = super.merge(
|
35
|
+
name: processor_name,
|
36
|
+
processor_type: :processor
|
37
|
+
)
|
38
|
+
|
39
|
+
unless errors.empty?
|
40
|
+
manifest[:error_classes] = errors.sort
|
41
|
+
end
|
42
|
+
|
43
|
+
manifest
|
44
|
+
end
|
45
|
+
|
46
|
+
def new_with_agnostic_args(**rest)
|
47
|
+
allowed_keys = %i[declaration_data parent_declaration_data]
|
48
|
+
|
49
|
+
invalid_keys = rest.keys - allowed_keys
|
50
|
+
|
51
|
+
unless invalid_keys.empty?
|
52
|
+
# :nocov:
|
53
|
+
raise ArgumentError, "Invalid keys: #{invalid_keys.join(", ")} expected one of #{allowed_keys.join(", ")}"
|
54
|
+
# :nocov:
|
55
|
+
end
|
56
|
+
|
57
|
+
args = []
|
58
|
+
|
59
|
+
if requires_declaration_data?
|
60
|
+
args << if rest.key?(:declaration_data)
|
61
|
+
rest[:declaration_data]
|
62
|
+
else
|
63
|
+
default_declaration_data
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if requires_parent_declaration_data?
|
68
|
+
args << rest[:parent_declaration_data] if requires_parent_declaration_data?
|
69
|
+
end
|
70
|
+
|
71
|
+
if args.empty? || args == [default_declaration_data]
|
72
|
+
instance
|
73
|
+
else
|
74
|
+
# TODO: This feels goofy that the positional types of this interface is dependent on these flags...
|
75
|
+
new(*args)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def instance
|
80
|
+
@instance ||= begin
|
81
|
+
if requires_parent_declaration_data?
|
82
|
+
# :nocov:
|
83
|
+
raise "Cannot treat processors dependent on parent declaration data as singletons"
|
84
|
+
# :nocov:
|
85
|
+
end
|
86
|
+
|
87
|
+
requires_declaration_data? ? new(default_declaration_data) : new
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def error_classes
|
92
|
+
@error_classes ||= begin
|
93
|
+
error_klasses = Util.constant_values(self, extends: Foobara::Error)
|
94
|
+
|
95
|
+
# TODO: we shouldn´t have wo ways to do this. But keeping this check for now until the old
|
96
|
+
# namespace implementation is removed.
|
97
|
+
error_klasses2 = if is_a?(Foobara::Namespace::IsNamespace)
|
98
|
+
foobara_all_error(mode: Namespace::LookupMode::DIRECT)
|
99
|
+
end
|
100
|
+
|
101
|
+
if error_klasses.sort_by(&:name) != error_klasses2.sort_by(&:name)
|
102
|
+
# :nocov:
|
103
|
+
raise "Expected #{error_klasses} to equal #{error_klasses2} for #{name}"
|
104
|
+
# :nocov:
|
105
|
+
end
|
106
|
+
|
107
|
+
if superclass < Processor
|
108
|
+
error_klasses2 += superclass.error_classes
|
109
|
+
end
|
110
|
+
|
111
|
+
error_klasses2
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def error_class
|
116
|
+
return @error_class if defined?(@error_class)
|
117
|
+
|
118
|
+
unless error_classes.size == 1
|
119
|
+
# :nocov:
|
120
|
+
raise "Expected exactly one error class to be defined for #{name} but has #{error_classes.size}"
|
121
|
+
# :nocov:
|
122
|
+
end
|
123
|
+
|
124
|
+
@error_class = error_classes.first
|
125
|
+
end
|
126
|
+
|
127
|
+
def symbol
|
128
|
+
@symbol ||= Util.non_full_name_underscore(self)&.gsub(/_(processor|transformer|validator)$/, "")&.to_sym
|
129
|
+
end
|
130
|
+
|
131
|
+
def requires_declaration_data?
|
132
|
+
true
|
133
|
+
end
|
134
|
+
|
135
|
+
def requires_parent_declaration_data?
|
136
|
+
false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
attr_accessor :declaration_data, :parent_declaration_data
|
141
|
+
attr_writer :created_in_namespace
|
142
|
+
|
143
|
+
def initialize(*args)
|
144
|
+
# TODO: get this out of here somehow?
|
145
|
+
unless Foobara::Namespace.current == Foobara
|
146
|
+
self.created_in_namespace = Foobara::Namespace.current
|
147
|
+
end
|
148
|
+
|
149
|
+
expected_arg_count = requires_declaration_data? ? 1 : 0
|
150
|
+
expected_arg_count += 1 if requires_parent_declaration_data?
|
151
|
+
|
152
|
+
unless expected_arg_count == args.count
|
153
|
+
# :nocov:
|
154
|
+
raise ArgumentError, "#{name} expected #{expected_arg_count} received #{args.count}"
|
155
|
+
# :nocov:
|
156
|
+
end
|
157
|
+
|
158
|
+
if requires_declaration_data?
|
159
|
+
self.declaration_data = args.shift
|
160
|
+
end
|
161
|
+
|
162
|
+
if requires_parent_declaration_data?
|
163
|
+
self.parent_declaration_data = args.first
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def created_in_namespace
|
168
|
+
# TODO: can we find a way to not depend on domains in this project?
|
169
|
+
@created_in_namespace ||= GlobalDomain
|
170
|
+
end
|
171
|
+
|
172
|
+
def name
|
173
|
+
self.class.processor_name
|
174
|
+
end
|
175
|
+
|
176
|
+
foobara_delegate :error_class,
|
177
|
+
:error_classes,
|
178
|
+
:symbol,
|
179
|
+
:requires_declaration_data?,
|
180
|
+
:requires_parent_declaration_data?,
|
181
|
+
to: :class
|
182
|
+
|
183
|
+
# Whoa, forgot this existed. Shouldn't we use this more?
|
184
|
+
def runner(value)
|
185
|
+
self.class::Runner.new(self, value)
|
186
|
+
end
|
187
|
+
|
188
|
+
# TODO: probably actually better to pass it through to the error class method. Bring that back.
|
189
|
+
def error_message(_value)
|
190
|
+
error_class.message
|
191
|
+
end
|
192
|
+
|
193
|
+
def error_context(_value)
|
194
|
+
error_class.context
|
195
|
+
end
|
196
|
+
|
197
|
+
def possible_errors
|
198
|
+
Foobara::Namespace.use created_in_namespace do
|
199
|
+
error_classes.map do |error_class|
|
200
|
+
PossibleError.new(error_class, processor: self)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# A transformer with no declaration data or with declaration data of false is considered to be
|
206
|
+
# not applicable. Override this wherever different behavior is needed.
|
207
|
+
def applicable?(_value)
|
208
|
+
always_applicable?
|
209
|
+
end
|
210
|
+
|
211
|
+
# This means its applicable regardless of value to transform. Override if different behavior is needed.
|
212
|
+
def always_applicable?
|
213
|
+
!!declaration_data
|
214
|
+
end
|
215
|
+
|
216
|
+
def process_value(_value)
|
217
|
+
# :nocov:
|
218
|
+
raise "subclass responsibility"
|
219
|
+
# :nocov:
|
220
|
+
end
|
221
|
+
|
222
|
+
def process_value!(value)
|
223
|
+
process_value(value).result!
|
224
|
+
end
|
225
|
+
|
226
|
+
def process_outcome(old_outcome)
|
227
|
+
return old_outcome if old_outcome.fatal?
|
228
|
+
|
229
|
+
value = old_outcome.result
|
230
|
+
|
231
|
+
return old_outcome unless applicable?(value)
|
232
|
+
|
233
|
+
process_value(value).tap do |outcome|
|
234
|
+
outcome.add_errors(old_outcome.errors)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def process_outcome!(old_outcome)
|
239
|
+
process_outcome(old_outcome).result!
|
240
|
+
end
|
241
|
+
|
242
|
+
def build_error(
|
243
|
+
value = nil,
|
244
|
+
error_class: self.error_class,
|
245
|
+
symbol: error_class.symbol,
|
246
|
+
message: error_message(value),
|
247
|
+
context: error_context(value),
|
248
|
+
path: error_path,
|
249
|
+
**
|
250
|
+
)
|
251
|
+
unless error_classes.include?(error_class)
|
252
|
+
# :nocov:
|
253
|
+
raise "invalid error"
|
254
|
+
# :nocov:
|
255
|
+
end
|
256
|
+
|
257
|
+
error_class.new(
|
258
|
+
path:,
|
259
|
+
message:,
|
260
|
+
context:,
|
261
|
+
symbol:,
|
262
|
+
**
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
266
|
+
# TODO: does this make sense to have something called attribute_name here??
|
267
|
+
def error_path
|
268
|
+
Util.array(attribute_name)
|
269
|
+
end
|
270
|
+
|
271
|
+
# TODO: this is a bit problematic. Maybe eliminate this instead of assuming it's generally useful
|
272
|
+
def attribute_name
|
273
|
+
nil
|
274
|
+
end
|
275
|
+
|
276
|
+
# Helps control when it runs in a pipeline
|
277
|
+
def priority
|
278
|
+
Priority::MEDIUM
|
279
|
+
end
|
280
|
+
|
281
|
+
def dup_processor(**opts)
|
282
|
+
valid_opts = %i[declaration_data parent_declaration_data]
|
283
|
+
|
284
|
+
invalid_opts = opts.keys - valid_opts
|
285
|
+
|
286
|
+
unless invalid_opts.empty?
|
287
|
+
# :nocov:
|
288
|
+
raise ArgumentError, "Invalid opts #{invalid_opts.inspect} expected only #{valid_opts.inspect}"
|
289
|
+
# :nocov:
|
290
|
+
end
|
291
|
+
|
292
|
+
declaration_data = if opts.key?(:declaration_data)
|
293
|
+
opts[:declaration_data]
|
294
|
+
else
|
295
|
+
self.declaration_data
|
296
|
+
end
|
297
|
+
parent_declaration_data = if opts.key?(:parent_declaration_data)
|
298
|
+
opts[:parent_declaration_data]
|
299
|
+
else
|
300
|
+
self.parent_declaration_data
|
301
|
+
end
|
302
|
+
|
303
|
+
self.class.new_with_agnostic_args(declaration_data:, parent_declaration_data:)
|
304
|
+
end
|
305
|
+
|
306
|
+
def inspect
|
307
|
+
s = super
|
308
|
+
|
309
|
+
if s.size > 400
|
310
|
+
# :nocov:
|
311
|
+
s = "#{s[0..400]}..."
|
312
|
+
# :nocov:
|
313
|
+
end
|
314
|
+
|
315
|
+
s
|
316
|
+
end
|
317
|
+
|
318
|
+
# TODO: is this in the wrong place? Should this be an extension?
|
319
|
+
|
320
|
+
def foobara_manifest(to_include:)
|
321
|
+
possible_errors = self.possible_errors.map do |possible_error|
|
322
|
+
[possible_error.key.to_s, possible_error.foobara_manifest(to_include:)]
|
323
|
+
end
|
324
|
+
|
325
|
+
manifest = super.dup
|
326
|
+
|
327
|
+
if scoped_category == :processor
|
328
|
+
to_include << self.class
|
329
|
+
manifest[:processor_class] = self.class.foobara_manifest_reference
|
330
|
+
end
|
331
|
+
|
332
|
+
if requires_declaration_data?
|
333
|
+
manifest[:declaration_data] = declaration_data
|
334
|
+
end
|
335
|
+
|
336
|
+
unless possible_errors.empty?
|
337
|
+
manifest[:possible_errors] = possible_errors.sort.to_h
|
338
|
+
end
|
339
|
+
|
340
|
+
manifest
|
341
|
+
end
|
342
|
+
|
343
|
+
def method_missing(method, *args, **opts)
|
344
|
+
if method == symbol
|
345
|
+
declaration_data
|
346
|
+
else
|
347
|
+
# :nocov:
|
348
|
+
super
|
349
|
+
# :nocov:
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def respond_to_missing?(method, private = false)
|
354
|
+
method == symbol || super
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|