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,189 @@
|
|
1
|
+
module Foobara
|
2
|
+
Foobara.require_project_file("builtin_types", "duck")
|
3
|
+
Foobara.require_project_file("builtin_types", "atomic_duck")
|
4
|
+
Foobara.require_project_file("builtin_types", "duckture")
|
5
|
+
|
6
|
+
module BuiltinTypes
|
7
|
+
class << self
|
8
|
+
foobara_delegate :global_type_declaration_handler_registry, to: TypeDeclarations
|
9
|
+
|
10
|
+
# TODO: break this up
|
11
|
+
def build_and_register!(
|
12
|
+
type_symbol,
|
13
|
+
base_type,
|
14
|
+
target_classes = const_get("::#{Util.classify(type_symbol)}"),
|
15
|
+
description: "Built-in #{type_symbol} type"
|
16
|
+
)
|
17
|
+
declaration_data = { type: type_symbol.to_sym }
|
18
|
+
|
19
|
+
module_symbol = Util.classify(type_symbol).to_sym
|
20
|
+
|
21
|
+
builtin_type_module = const_get(module_symbol, false)
|
22
|
+
|
23
|
+
casters_module = Util.constant_value(builtin_type_module, :Casters)
|
24
|
+
caster_classes = if casters_module
|
25
|
+
Util.constant_values(casters_module, extends: Value::Processor)
|
26
|
+
end
|
27
|
+
casters = caster_classes&.map do |caster_class|
|
28
|
+
caster_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
|
29
|
+
end
|
30
|
+
|
31
|
+
transformers_module = Util.constant_value(builtin_type_module, :Transformers)
|
32
|
+
transformer_classes = if transformers_module
|
33
|
+
Util.constant_values(transformers_module, extends: Value::Processor)
|
34
|
+
end
|
35
|
+
transformers = transformer_classes&.map do |transformer_class|
|
36
|
+
transformer_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
|
37
|
+
end || []
|
38
|
+
|
39
|
+
validators_module = Util.constant_value(builtin_type_module, :Validators)
|
40
|
+
validator_classes = if validators_module
|
41
|
+
Util.constant_values(validators_module, extends: Value::Processor)
|
42
|
+
end
|
43
|
+
validators = validator_classes&.map do |validator_class|
|
44
|
+
validator_class.new_with_agnostic_args(parent_declaration_data: declaration_data)
|
45
|
+
end || []
|
46
|
+
|
47
|
+
type = Foobara::Types::Type.new(
|
48
|
+
declaration_data,
|
49
|
+
base_type:,
|
50
|
+
name: type_symbol,
|
51
|
+
casters:,
|
52
|
+
transformers:,
|
53
|
+
validators:,
|
54
|
+
# TODO: this is for controlling casting or not casting but could give the wrong information from a
|
55
|
+
# reflection point of view...
|
56
|
+
target_classes:,
|
57
|
+
description:
|
58
|
+
)
|
59
|
+
|
60
|
+
builtin_types << type
|
61
|
+
|
62
|
+
# TODO: is this necessary?
|
63
|
+
Foobara::Namespace::NamespaceHelpers.foobara_namespace!(type)
|
64
|
+
|
65
|
+
# TODO: really need to encapsulate this somehow...
|
66
|
+
type.type_symbol = type_symbol
|
67
|
+
type.foobara_parent_namespace ||= GlobalDomain
|
68
|
+
type.foobara_parent_namespace.foobara_register(type)
|
69
|
+
|
70
|
+
supported_casters_module = Util.constant_value(builtin_type_module, :SupportedCasters)
|
71
|
+
supported_caster_classes = if supported_casters_module
|
72
|
+
Util.constant_values(supported_casters_module, extends: Value::Processor)
|
73
|
+
end
|
74
|
+
supported_transformers_module = Util.constant_value(builtin_type_module, :SupportedTransformers)
|
75
|
+
supported_transformer_classes = if supported_transformers_module
|
76
|
+
Util.constant_values(supported_transformers_module, extends: Value::Processor)
|
77
|
+
end
|
78
|
+
supported_validators_module = Util.constant_value(builtin_type_module, :SupportedValidators)
|
79
|
+
supported_validator_classes = if supported_validators_module
|
80
|
+
Util.constant_values(supported_validators_module, extends: Value::Processor)
|
81
|
+
end
|
82
|
+
supported_processors_module = Util.constant_value(builtin_type_module, :SupportedProcessors)
|
83
|
+
supported_processor_classes = if supported_processors_module
|
84
|
+
Util.constant_values(supported_processors_module, extends: Value::Processor)
|
85
|
+
end
|
86
|
+
|
87
|
+
processor_classes = [*transformers, *validators].map(&:class)
|
88
|
+
|
89
|
+
[
|
90
|
+
*supported_caster_classes,
|
91
|
+
*supported_transformer_classes,
|
92
|
+
*supported_validator_classes,
|
93
|
+
*supported_processor_classes
|
94
|
+
].each do |processor_class|
|
95
|
+
type.register_supported_processor_class(processor_class)
|
96
|
+
processor_classes << processor_class
|
97
|
+
end
|
98
|
+
|
99
|
+
processor_classes.each do |processor_class|
|
100
|
+
install_type_declaration_extensions_for(processor_class)
|
101
|
+
end
|
102
|
+
|
103
|
+
[
|
104
|
+
[casters_module, caster_classes, casters],
|
105
|
+
[transformers_module, transformer_classes, transformers],
|
106
|
+
[validators_module, validator_classes, validators],
|
107
|
+
[supported_casters_module, supported_caster_classes],
|
108
|
+
[supported_processors_module, supported_processor_classes],
|
109
|
+
[supported_transformers_module, supported_transformer_classes],
|
110
|
+
[supported_validators_module, supported_validator_classes]
|
111
|
+
].each do |(mod, klasses, instances)|
|
112
|
+
next unless mod
|
113
|
+
|
114
|
+
prefix = Util.non_full_name(mod)
|
115
|
+
|
116
|
+
[*klasses, *instances].each do |scoped|
|
117
|
+
if !scoped.scoped_path_set? || scoped.scoped_path_autoset?
|
118
|
+
# TODO: Do we actually need this?
|
119
|
+
short_name = Util.non_full_name(scoped)
|
120
|
+
short_name = Util.underscore(short_name) unless scoped.is_a?(::Class)
|
121
|
+
|
122
|
+
scoped.scoped_path = [prefix, short_name]
|
123
|
+
end
|
124
|
+
|
125
|
+
parent = scoped.scoped_namespace
|
126
|
+
|
127
|
+
if parent.nil? || parent == Foobara || parent == Namespace.global || parent == GlobalDomain
|
128
|
+
scoped.foobara_parent_namespace = type
|
129
|
+
type.foobara_register(scoped)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
type
|
135
|
+
end
|
136
|
+
|
137
|
+
def install_type_declaration_extensions_for(processor_class)
|
138
|
+
extension_module = Util.constant_value(processor_class, :TypeDeclarationExtension)
|
139
|
+
|
140
|
+
return unless extension_module
|
141
|
+
|
142
|
+
Util.constant_values(extension_module, is_a: ::Module).each do |handler_module|
|
143
|
+
handler_name = Util.non_full_name(handler_module)
|
144
|
+
handler_class_to_extend = TypeDeclarations::Handlers.const_get(handler_name)
|
145
|
+
|
146
|
+
unless handler_class_to_extend
|
147
|
+
# :nocov:
|
148
|
+
raise "Couldn't find handler class for #{handler_name}"
|
149
|
+
# :nocov:
|
150
|
+
end
|
151
|
+
|
152
|
+
handler_to_extend = global_type_declaration_handler_registry.type_declaration_handler_for_handler_class(
|
153
|
+
handler_class_to_extend
|
154
|
+
)
|
155
|
+
|
156
|
+
unless handler_to_extend
|
157
|
+
# :nocov:
|
158
|
+
raise "Could not find a handler for #{handler_class_to_extend}"
|
159
|
+
# :nocov:
|
160
|
+
end
|
161
|
+
|
162
|
+
desugarizer_module = Util.constant_value(handler_module, :Desugarizers)
|
163
|
+
|
164
|
+
if desugarizer_module
|
165
|
+
desugarizer_classes = Util.constant_values(desugarizer_module, is_a: ::Class)
|
166
|
+
|
167
|
+
desugarizer_classes.each do |desugarizer_class|
|
168
|
+
desugarizer = desugarizer_class.instance
|
169
|
+
|
170
|
+
handler_to_extend.desugarizers << desugarizer
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
validator_module = Util.constant_value(handler_module, :TypeDeclarationValidators)
|
175
|
+
|
176
|
+
if validator_module
|
177
|
+
validator_classes = Util.constant_values(validator_module, is_a: Class)
|
178
|
+
|
179
|
+
validator_classes.each do |validator_class|
|
180
|
+
validator = validator_class.instance
|
181
|
+
|
182
|
+
handler_to_extend.type_declaration_validators << validator
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Date
|
4
|
+
module Casters
|
5
|
+
class Hash < Value::Caster
|
6
|
+
def applicable?(hash)
|
7
|
+
hash.is_a?(::Hash) && hash.keys.size == 3 && (hash.keys.map(&:to_s).sort == %w[day month year])
|
8
|
+
end
|
9
|
+
|
10
|
+
def applies_message
|
11
|
+
"be a Hash with :year, :month, and :day keys"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(hash)
|
15
|
+
hash = Util.symbolize_keys(hash)
|
16
|
+
|
17
|
+
::Date.new(hash[:year], hash[:month], hash[:day])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Date
|
4
|
+
module Casters
|
5
|
+
class String < Value::Caster
|
6
|
+
def applicable?(value)
|
7
|
+
value.is_a?(::String) && parse(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def applies_message
|
11
|
+
"be a valid date string with year-month-day order"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(string)
|
15
|
+
parse(string)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
NOT_DELIMITED_REGEX = /\A(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})\z/
|
21
|
+
DELIMITED_REGEX = /\A(?<year>\d{4,})(?<delimiter>[\/\\.|_:;-])(?<month>\d{1,2})\k<delimiter>(?<day>\d{1,2})\z/
|
22
|
+
|
23
|
+
def parse(string)
|
24
|
+
match = NOT_DELIMITED_REGEX.match(string) || DELIMITED_REGEX.match(string)
|
25
|
+
|
26
|
+
if match
|
27
|
+
year = match[:year].to_i
|
28
|
+
month = match[:month].to_i
|
29
|
+
day = match[:day].to_i
|
30
|
+
|
31
|
+
if ::Date.valid_date?(year, month, day)
|
32
|
+
::Date.new(year, month, day)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Datetime
|
4
|
+
module Casters
|
5
|
+
class Date < Value::Caster
|
6
|
+
def applicable?(value)
|
7
|
+
value.is_a?(::Date)
|
8
|
+
end
|
9
|
+
|
10
|
+
def applies_message
|
11
|
+
"be a Date"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(date)
|
15
|
+
date.to_time
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Datetime
|
4
|
+
module Casters
|
5
|
+
# TODO: there seems to be an issue with the design here. We cast first and casters are
|
6
|
+
# transformers (don't return errors.) However, it would probably give a better error if we could
|
7
|
+
# indicate exactly what was wrong with this hash instead of a catch-all error mixed with all the other
|
8
|
+
# casters errors. The obvious solution is to inherit Value::Processor instead. Maybe that would just work
|
9
|
+
# without any other changes needed.
|
10
|
+
# TODO: try that
|
11
|
+
class Hash < TypeDeclarations::Caster
|
12
|
+
def applicable?(hash)
|
13
|
+
hash.is_a?(::Hash) && valid_hash?(hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
def applies_message
|
17
|
+
"be a Hash with :year, :month, :day, :hours, :minutes, :seconds, :milliseconds, and :zone keys"
|
18
|
+
end
|
19
|
+
|
20
|
+
def cast(hash)
|
21
|
+
hash = datetime_attributes_type.process_value!(hash)
|
22
|
+
|
23
|
+
year = hash[:year]
|
24
|
+
month = hash[:month]
|
25
|
+
day = hash[:day]
|
26
|
+
hours = hash[:hours]
|
27
|
+
minutes = hash[:minutes]
|
28
|
+
seconds = hash[:seconds]
|
29
|
+
milliseconds = hash[:milliseconds]
|
30
|
+
zone = hash[:zone]
|
31
|
+
|
32
|
+
if milliseconds
|
33
|
+
seconds = seconds.to_r + (milliseconds.to_r / 1000)
|
34
|
+
end
|
35
|
+
|
36
|
+
::Time.new(year, month, day, hours, minutes, seconds, zone)
|
37
|
+
end
|
38
|
+
|
39
|
+
def datetime_attributes_type
|
40
|
+
@datetime_attributes_type ||= type_for_declaration(
|
41
|
+
year: :integer,
|
42
|
+
month: { type: :integer, min: 1, max: 12 },
|
43
|
+
day: { type: :integer, min: 1, max: 31 },
|
44
|
+
hours: { type: :integer, min: 0, max: 23, required: false, default: 0 },
|
45
|
+
minutes: { type: :integer, min: 0, max: 59, required: false, default: 0 },
|
46
|
+
seconds: { type: :big_decimal, min: 0, max: 59, required: false, default: 0 },
|
47
|
+
milliseconds: { type: :integer, min: 0, max: 1000, required: false },
|
48
|
+
zone: { type: :string, required: false }
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def valid_hash?(hash)
|
55
|
+
# TODO: use a #runner to memoize this?
|
56
|
+
outcome = datetime_attributes_type.process_value(hash)
|
57
|
+
|
58
|
+
if outcome.success?
|
59
|
+
hash = outcome.result
|
60
|
+
|
61
|
+
year = hash[:year]
|
62
|
+
month = hash[:month]
|
63
|
+
day = hash[:day]
|
64
|
+
zone = hash[:zone]
|
65
|
+
|
66
|
+
::Date.valid_date?(year, month, day) && (zone.nil? || valid_zone?(zone))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def valid_zone?(zone)
|
71
|
+
!!Time.zone_offset(zone)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Datetime
|
4
|
+
module Casters
|
5
|
+
class SecondsSinceEpoch < Value::Caster
|
6
|
+
def applicable?(value)
|
7
|
+
value.is_a?(::Integer)
|
8
|
+
end
|
9
|
+
|
10
|
+
def applies_message
|
11
|
+
"be a an integer representing seconds since epoch"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(seconds_since_epoch)
|
15
|
+
Time.at(seconds_since_epoch)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Datetime
|
4
|
+
module Casters
|
5
|
+
class String < Value::Caster
|
6
|
+
def applicable?(value)
|
7
|
+
value.is_a?(::String) && parse(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def applies_message
|
11
|
+
"be a valid date string"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(string)
|
15
|
+
parse(string)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse(string)
|
21
|
+
# would be nice to do this some other way where we can verify against a regex independent of casting
|
22
|
+
# to a Time especially since ArgumentError is way too generic. But might have to just stick with this
|
23
|
+
::Time.parse(string)
|
24
|
+
rescue ArgumentError
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedCasters
|
5
|
+
class AllowNil < TypeDeclarations::Caster
|
6
|
+
class << self
|
7
|
+
def requires_declaration_data?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_declaration_data
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def applicable?(value)
|
16
|
+
value.nil? && allow_nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def allow_nil?
|
20
|
+
declaration_data
|
21
|
+
end
|
22
|
+
|
23
|
+
def cast(value)
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
27
|
+
def applies_message
|
28
|
+
"be nil"
|
29
|
+
end
|
30
|
+
|
31
|
+
def priority
|
32
|
+
Priority::HIGH
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedValidators
|
5
|
+
class InstanceOf < TypeDeclarations::Validator
|
6
|
+
module TypeDeclarationExtension
|
7
|
+
module ExtendRegisteredTypeDeclaration
|
8
|
+
module Desugarizers
|
9
|
+
class ClassDesugarizer < TypeDeclarations::Desugarizer
|
10
|
+
def applicable?(rawish_type_declaration)
|
11
|
+
rawish_type_declaration.is_a?(::Class)
|
12
|
+
end
|
13
|
+
|
14
|
+
def desugarize(rawish_type_declaration)
|
15
|
+
{ type: :duck, instance_of: rawish_type_declaration.name }
|
16
|
+
end
|
17
|
+
|
18
|
+
def priority
|
19
|
+
Priority::LOWEST + 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedValidators
|
5
|
+
class InstanceOf < TypeDeclarations::Validator
|
6
|
+
module TypeDeclarationExtension
|
7
|
+
module ExtendRegisteredTypeDeclaration
|
8
|
+
module Desugarizers
|
9
|
+
class InstanceOfClassDesugarizer < TypeDeclarations::Desugarizer
|
10
|
+
def applicable?(rawish_type_declaration)
|
11
|
+
rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:instance_of].is_a?(::Class)
|
12
|
+
end
|
13
|
+
|
14
|
+
def desugarize(rawish_type_declaration)
|
15
|
+
instance_of = rawish_type_declaration[:instance_of]
|
16
|
+
instance_of = instance_of.name
|
17
|
+
rawish_type_declaration.merge(instance_of:)
|
18
|
+
end
|
19
|
+
|
20
|
+
def priority
|
21
|
+
Priority::LOWEST + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedValidators
|
5
|
+
class InstanceOf < TypeDeclarations::Validator
|
6
|
+
module TypeDeclarationExtension
|
7
|
+
module ExtendRegisteredTypeDeclaration
|
8
|
+
module Desugarizers
|
9
|
+
class InstanceOfSymbolDesugarizer < TypeDeclarations::Desugarizer
|
10
|
+
def applicable?(rawish_type_declaration)
|
11
|
+
rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:instance_of].is_a?(::Symbol)
|
12
|
+
end
|
13
|
+
|
14
|
+
def desugarize(rawish_type_declaration)
|
15
|
+
instance_of = rawish_type_declaration[:instance_of]
|
16
|
+
instance_of = instance_of.to_s
|
17
|
+
rawish_type_declaration.merge(instance_of:)
|
18
|
+
end
|
19
|
+
|
20
|
+
def priority
|
21
|
+
Priority::LOWEST + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedValidators
|
5
|
+
class InstanceOf < TypeDeclarations::Validator
|
6
|
+
module TypeDeclarationExtension
|
7
|
+
module ExtendRegisteredTypeDeclaration
|
8
|
+
module TypeDeclarationValidators
|
9
|
+
class IsValidClass < TypeDeclarations::TypeDeclarationValidator
|
10
|
+
class InvalidInstanceOfValueGivenError < Value::DataError
|
11
|
+
class << self
|
12
|
+
def message
|
13
|
+
"instance_of: should be a class or the name of an existing class"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def applicable?(strict_type_declaration)
|
19
|
+
strict_type_declaration.is_a?(Hash) && strict_type_declaration.key?(:instance_of)
|
20
|
+
end
|
21
|
+
|
22
|
+
def validation_errors(strict_type_declaration)
|
23
|
+
instance_of = strict_type_declaration[:instance_of]
|
24
|
+
|
25
|
+
return if instance_of.is_a?(::Class)
|
26
|
+
|
27
|
+
if instance_of.is_a?(::String) || instance_of.is_a?(::Symbol)
|
28
|
+
unless Object.const_defined?(instance_of)
|
29
|
+
build_error(context: { attribute_name: :instance_of, value: instance_of })
|
30
|
+
end
|
31
|
+
else
|
32
|
+
build_error(context: { attribute_name: :instance_of, value: instance_of })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Foobara
|
2
|
+
module BuiltinTypes
|
3
|
+
module Duck
|
4
|
+
module SupportedValidators
|
5
|
+
class InstanceOf < TypeDeclarations::Validator
|
6
|
+
class NotInstanceOfError < Foobara::Value::DataError
|
7
|
+
class << self
|
8
|
+
def context_type_declaration
|
9
|
+
{
|
10
|
+
value: :duck,
|
11
|
+
expected_class_name: :string
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def expected_class_name
|
18
|
+
declaration_data
|
19
|
+
end
|
20
|
+
|
21
|
+
def validation_errors(value)
|
22
|
+
klass = Object.const_get(expected_class_name)
|
23
|
+
unless value.is_a?(klass)
|
24
|
+
build_error(value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def error_message(value)
|
29
|
+
"#{value} is not an instance of #{expected_class_name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def error_context(value)
|
33
|
+
{
|
34
|
+
value:,
|
35
|
+
expected_class_name:
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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 CastOneOf < TypeDeclarations::Desugarizer
|
10
|
+
def applicable?(rawish_type_declaration)
|
11
|
+
rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:one_of].is_a?(::Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
def desugarize(rawish_type_declaration)
|
15
|
+
one_of = rawish_type_declaration[:one_of]
|
16
|
+
|
17
|
+
type = type_for_declaration(rawish_type_declaration.except(:one_of))
|
18
|
+
|
19
|
+
one_of = one_of.map do |value|
|
20
|
+
type.process_value!(value)
|
21
|
+
end
|
22
|
+
|
23
|
+
rawish_type_declaration.merge(one_of:)
|
24
|
+
end
|
25
|
+
|
26
|
+
def priority
|
27
|
+
Priority::LOW + 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|