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,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Duck
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class OneOf < TypeDeclarations::Validator
|
|
6
|
+
module TypeDeclarationExtension
|
|
7
|
+
module ExtendRegisteredTypeDeclaration
|
|
8
|
+
module Desugarizers
|
|
9
|
+
class ModuleDesugarizer < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(rawish_type_declaration)
|
|
11
|
+
rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:one_of].is_a?(::Module)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def desugarize(rawish_type_declaration)
|
|
15
|
+
mod = rawish_type_declaration[:one_of]
|
|
16
|
+
|
|
17
|
+
one_of = Util.constant_values(mod)
|
|
18
|
+
|
|
19
|
+
one_of = begin
|
|
20
|
+
one_of.sort
|
|
21
|
+
rescue
|
|
22
|
+
# :nocov:
|
|
23
|
+
one_of.sort_by(&:inspect)
|
|
24
|
+
# :nocov:
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
rawish_type_declaration.merge(one_of:)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def priority
|
|
31
|
+
Priority::LOW
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Duck
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class OneOf < TypeDeclarations::Validator
|
|
6
|
+
class ValueNotValidError < Foobara::Value::DataError
|
|
7
|
+
class << self
|
|
8
|
+
def context_type_declaration
|
|
9
|
+
{
|
|
10
|
+
value: :duck,
|
|
11
|
+
valid_values: [:duck]
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def valid_values
|
|
18
|
+
declaration_data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def validation_errors(value)
|
|
22
|
+
unless valid_values.include?(value)
|
|
23
|
+
build_error(value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_message(value)
|
|
28
|
+
"#{value} is not one of #{valid_values}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def error_context(value)
|
|
32
|
+
{
|
|
33
|
+
value:,
|
|
34
|
+
valid_values:
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Email
|
|
4
|
+
module Transformers
|
|
5
|
+
# Seems like it might be cleaner to just assemble these parts in one place instead of in different files?
|
|
6
|
+
# Hard to say.
|
|
7
|
+
class Downcase < BuiltinTypes::String::SupportedTransformers::Downcase
|
|
8
|
+
def always_applicable?
|
|
9
|
+
true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Email
|
|
4
|
+
class ValidatorBase < TypeDeclarations::Validator
|
|
5
|
+
singleton_class.define_method :error_classes do
|
|
6
|
+
@error_classes ||= begin
|
|
7
|
+
error_short_name = "#{Util.non_full_name(self)}Error"
|
|
8
|
+
error_class_name = "#{name}::#{error_short_name}"
|
|
9
|
+
|
|
10
|
+
error_class = Util.make_class(error_class_name, Value::DataError) do
|
|
11
|
+
class << self
|
|
12
|
+
def context_type_declaration
|
|
13
|
+
{
|
|
14
|
+
value: :duck,
|
|
15
|
+
regex: :duck, # TODO: make regex type
|
|
16
|
+
negate_regex: :duck # TODO: make :boolean
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def message
|
|
21
|
+
Util.humanize(symbol)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[error_class]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def always_applicable?
|
|
31
|
+
true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def regex
|
|
35
|
+
# :nocov:
|
|
36
|
+
raise "subclass responsibility"
|
|
37
|
+
# :nocov:
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def negate_regex?
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def error_context(value)
|
|
45
|
+
{
|
|
46
|
+
value:,
|
|
47
|
+
regex:,
|
|
48
|
+
negate_regex: negate_regex?
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def validation_errors(email)
|
|
53
|
+
build_error if email.send(negate_regex? ? :=~ : :!~, regex)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
module Validators
|
|
58
|
+
# This is getting kind of convoluted. TODO: unroll all of this into different files instead of dynamically
|
|
59
|
+
# creating classes here
|
|
60
|
+
{
|
|
61
|
+
true => {
|
|
62
|
+
must_have_an_at_sign: /\A[^@]+\z/,
|
|
63
|
+
cannot_have_multiple_at_signs: /@.*@/,
|
|
64
|
+
first_part_cannot_start_with_or_end_with_a_dot_or_have_two_dots_in_a_row: /(^\.|\.@|\.\..*@)/,
|
|
65
|
+
domain_cannot_start_with_or_end_with_a_hyphen: /(@-|-$)/,
|
|
66
|
+
first_part_cannot_be_empty: /\A@/,
|
|
67
|
+
second_part_cannot_be_empty: /@\z/
|
|
68
|
+
},
|
|
69
|
+
false => {
|
|
70
|
+
cannot_exceed_64_characters: /\A.{0,64}\z/,
|
|
71
|
+
first_part_has_bad_characters: /\A[.a-z\d_!#$%&'*+\/=?^‘{|}~-]+@/,
|
|
72
|
+
second_part_has_bad_characters: /@[.a-z\d-]+\z/
|
|
73
|
+
}
|
|
74
|
+
}.each do |negate, rule_set|
|
|
75
|
+
rule_set.each_pair do |symbol, regex|
|
|
76
|
+
class_name = "#{name}::#{Util.classify(symbol)}"
|
|
77
|
+
|
|
78
|
+
Util.make_class(class_name, ValidatorBase) do
|
|
79
|
+
define_method :regex do
|
|
80
|
+
regex
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if negate
|
|
84
|
+
define_method :negate_regex? do
|
|
85
|
+
true
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Float
|
|
4
|
+
module Casters
|
|
5
|
+
class Integer < Value::Caster
|
|
6
|
+
def applicable?(value)
|
|
7
|
+
value.is_a?(::Integer)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def applies_message
|
|
11
|
+
"be a an Integer"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cast(integer)
|
|
15
|
+
integer.to_f
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Float
|
|
4
|
+
module Casters
|
|
5
|
+
class String < Value::Caster
|
|
6
|
+
FLOAT_REGEX = /^-?\d+(\.\d+)?([eE]-?\d+)?$/
|
|
7
|
+
|
|
8
|
+
def applicable?(value)
|
|
9
|
+
value.is_a?(::String) && value =~ FLOAT_REGEX
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def applies_message
|
|
13
|
+
"be a string of digits with one decimal point optionally amongst " \
|
|
14
|
+
"them and optionally with a minus sign in front and optionally an exponent denoted with e"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cast(string)
|
|
18
|
+
string.to_f
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Integer
|
|
4
|
+
module Casters
|
|
5
|
+
class String < Value::Caster
|
|
6
|
+
INTEGER_REGEX = /^-?\d+$/
|
|
7
|
+
|
|
8
|
+
def applicable?(value)
|
|
9
|
+
value.is_a?(::String) && value =~ INTEGER_REGEX
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def applies_message
|
|
13
|
+
"be a string of digits optionally with a minus sign in front"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def cast(string)
|
|
17
|
+
string.to_i
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Number
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class Max < TypeDeclarations::Validator
|
|
6
|
+
class MaxExceededError < Foobara::Value::DataError
|
|
7
|
+
class << self
|
|
8
|
+
def context_type_declaration
|
|
9
|
+
{
|
|
10
|
+
value: :number,
|
|
11
|
+
max: :number
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def max
|
|
18
|
+
declaration_data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def validation_errors(value)
|
|
22
|
+
if value > max
|
|
23
|
+
build_error(value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_message(value)
|
|
28
|
+
"Max exceeded. #{value} is larger than #{max}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def error_context(value)
|
|
32
|
+
{
|
|
33
|
+
value:,
|
|
34
|
+
max:
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Number
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class Min < TypeDeclarations::Validator
|
|
6
|
+
class BelowMinimumError < Foobara::Value::DataError
|
|
7
|
+
class << self
|
|
8
|
+
def context_type_declaration
|
|
9
|
+
{
|
|
10
|
+
value: :number,
|
|
11
|
+
min: :number
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def min
|
|
18
|
+
declaration_data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def validation_errors(value)
|
|
22
|
+
if value < min
|
|
23
|
+
build_error(value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_message(value)
|
|
28
|
+
"Below minimum allowed. #{value} is less than #{min}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def error_context(value)
|
|
32
|
+
{
|
|
33
|
+
value:,
|
|
34
|
+
min:
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module String
|
|
4
|
+
module Casters
|
|
5
|
+
class Numeric < Value::Caster
|
|
6
|
+
def applicable?(value)
|
|
7
|
+
value.is_a?(::Numeric)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def applies_message
|
|
11
|
+
"be a Numeric"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cast(string)
|
|
15
|
+
string.to_s
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module String
|
|
4
|
+
module Casters
|
|
5
|
+
class Symbol < Value::Caster
|
|
6
|
+
def applicable?(value)
|
|
7
|
+
value.is_a?(::Symbol)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def applies_message
|
|
11
|
+
"be a Symbol"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cast(string)
|
|
15
|
+
string.to_s
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
# TODO: Rename to StringType to avoid needing to remember ::String elsewhere in the code
|
|
4
|
+
module String
|
|
5
|
+
module SupportedTransformers
|
|
6
|
+
class Downcase < Value::Transformer.subclass(transform: :downcase.to_proc, name: "Downcase")
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module String
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class Matches < TypeDeclarations::Validator
|
|
6
|
+
class DoesNotMatchError < Foobara::Value::DataError
|
|
7
|
+
class << self
|
|
8
|
+
def context_type_declaration
|
|
9
|
+
{
|
|
10
|
+
value: :string,
|
|
11
|
+
regex: :duck # TODO: make a regex type??
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def regex
|
|
18
|
+
declaration_data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def validation_errors(string)
|
|
22
|
+
if string !~ regex
|
|
23
|
+
build_error(string)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_message(value)
|
|
28
|
+
"#{value.inspect} did not match #{regex.inspect}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def error_context(value)
|
|
32
|
+
{
|
|
33
|
+
value:,
|
|
34
|
+
regex: regex.to_s
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module String
|
|
4
|
+
module SupportedValidators
|
|
5
|
+
class MaxLength < TypeDeclarations::Validator
|
|
6
|
+
class MaxLengthExceededError < Foobara::Value::DataError
|
|
7
|
+
class << self
|
|
8
|
+
def context_type_declaration
|
|
9
|
+
{
|
|
10
|
+
value: :string,
|
|
11
|
+
max_length: :integer
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def validation_errors(string)
|
|
18
|
+
if string.length > max_length
|
|
19
|
+
build_error(string)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def error_message(_value)
|
|
24
|
+
"Max length exceeded. Cannot be longer than #{max_length}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_context(value)
|
|
28
|
+
{
|
|
29
|
+
value:,
|
|
30
|
+
max_length:
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Symbol
|
|
4
|
+
module Casters
|
|
5
|
+
class String < Value::Caster
|
|
6
|
+
def applicable?(value)
|
|
7
|
+
value.is_a?(::String)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def applies_message
|
|
11
|
+
"be a String"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cast(string)
|
|
15
|
+
string.to_sym
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Tuple
|
|
4
|
+
module SupportedProcessors
|
|
5
|
+
class ElementTypeDeclarations < TypeDeclarations::ElementProcessor
|
|
6
|
+
module TypeDeclarationExtension
|
|
7
|
+
module ExtendTupleTypeDeclaration
|
|
8
|
+
module Desugarizers
|
|
9
|
+
class SetSize < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(value)
|
|
11
|
+
if value.is_a?(::Hash)
|
|
12
|
+
value.key?(:element_type_declarations) && value[:type] == :tuple && !value.key?(:size)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def desugarize(rawish_type_declaration)
|
|
17
|
+
rawish_type_declaration[:size] = rawish_type_declaration[:element_type_declarations].size
|
|
18
|
+
rawish_type_declaration
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def priority
|
|
22
|
+
Priority::LOW
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Tuple
|
|
4
|
+
module SupportedProcessors
|
|
5
|
+
class ElementTypeDeclarations < TypeDeclarations::ElementProcessor
|
|
6
|
+
module TypeDeclarationExtension
|
|
7
|
+
module ExtendTupleTypeDeclaration
|
|
8
|
+
module TypeDeclarationValidators
|
|
9
|
+
class SizeMatches < TypeDeclarations::TypeDeclarationValidator
|
|
10
|
+
class IncorrectSizeError < Value::DataError
|
|
11
|
+
class << self
|
|
12
|
+
def context_type_declaration
|
|
13
|
+
{
|
|
14
|
+
expected_size: :integer,
|
|
15
|
+
actual_size: :integer,
|
|
16
|
+
value: :array
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def applicable?(strict_type_declaration)
|
|
23
|
+
strict_type_declaration.key?(:size)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def validation_errors(strict_type_declaration)
|
|
27
|
+
size = strict_type_declaration[:size]
|
|
28
|
+
element_type_declarations = strict_type_declaration[:element_type_declarations]
|
|
29
|
+
element_type_declarations_size = element_type_declarations.size
|
|
30
|
+
|
|
31
|
+
if size != element_type_declarations_size
|
|
32
|
+
build_error(
|
|
33
|
+
message: "Expected tuple to have #{size} elements but it had #{element_type_declarations_size}",
|
|
34
|
+
context: {
|
|
35
|
+
expected_size: size,
|
|
36
|
+
actual_size: element_type_declarations_size,
|
|
37
|
+
value: strict_type_declaration
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module BuiltinTypes
|
|
3
|
+
module Tuple
|
|
4
|
+
module SupportedProcessors
|
|
5
|
+
# TODO: how to relate size to this? I guess a TypeDeclarationValidator is a good idea here to make sure
|
|
6
|
+
# that element_type_declarations.size matches size if both are present and a Desugarizer that sets them both?
|
|
7
|
+
class ElementTypeDeclarations < TypeDeclarations::ElementProcessor
|
|
8
|
+
def applicable?(value)
|
|
9
|
+
# Size mismatch is handled by size validator later so just bail out here since without a correct
|
|
10
|
+
# size we don't really know what to expect to happen if we proceed.
|
|
11
|
+
# TODO: would be nice to have the Size validator run earlier in the process so that we wouldn't have
|
|
12
|
+
# to check this here.
|
|
13
|
+
value.size == element_type_declarations.size
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def element_types
|
|
17
|
+
@element_types ||= element_type_declarations.map do |type_declaration|
|
|
18
|
+
type_for_declaration(type_declaration)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def process_value(array)
|
|
23
|
+
errors = []
|
|
24
|
+
|
|
25
|
+
array.each.with_index do |element, index|
|
|
26
|
+
element_outcome = element_types[index].process_value(element)
|
|
27
|
+
|
|
28
|
+
if element_outcome.success?
|
|
29
|
+
array[index] = element_outcome.result
|
|
30
|
+
else
|
|
31
|
+
element_outcome.each_error do |error|
|
|
32
|
+
error.prepend_path!(index)
|
|
33
|
+
|
|
34
|
+
errors << error
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Outcome.new(result: array, errors:)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def possible_errors
|
|
43
|
+
possibilities = super.dup
|
|
44
|
+
|
|
45
|
+
element_types.each.with_index do |element_type, index|
|
|
46
|
+
element_type.possible_errors.each do |possible_error|
|
|
47
|
+
possible_error = possible_error.dup
|
|
48
|
+
possible_error.prepend_path!(index)
|
|
49
|
+
possibilities << possible_error
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
possibilities
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module Foobara::Callback; end
|