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,69 @@
|
|
1
|
+
module Foobara
|
2
|
+
class StateMachine
|
3
|
+
module Validations
|
4
|
+
include Concern
|
5
|
+
|
6
|
+
class UnexpectedTerminalStates < StandardError; end
|
7
|
+
class MissingStates < StandardError; end
|
8
|
+
class ExtraStates < StandardError; end
|
9
|
+
class MissingTransitions < StandardError; end
|
10
|
+
class ExtraTransitions < StandardError; end
|
11
|
+
class MissingTerminalStates < StandardError; end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def validate_terminal_states(computed_terminal_states, all_states)
|
15
|
+
unexpected_terminal_states = computed_terminal_states - terminal_states
|
16
|
+
|
17
|
+
unless unexpected_terminal_states.empty?
|
18
|
+
raise UnexpectedTerminalStates, "#{
|
19
|
+
unexpected_terminal_states
|
20
|
+
} do(es) not have transitions even though they are not in the explicit list of terminal states #{
|
21
|
+
terminal_states
|
22
|
+
}"
|
23
|
+
end
|
24
|
+
|
25
|
+
missing_terminal_states = terminal_states - all_states
|
26
|
+
|
27
|
+
unless missing_terminal_states.empty?
|
28
|
+
raise MissingTerminalStates, "#{
|
29
|
+
missing_terminal_states
|
30
|
+
} was/were included explicitly in terminal_states but didn't appear in the transition map"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_states(computed_states)
|
35
|
+
missing_states = states - computed_states
|
36
|
+
|
37
|
+
unless missing_states.empty?
|
38
|
+
raise MissingStates,
|
39
|
+
"#{missing_states} is/are explicitly declared as states but do(es)n't appear in the transition map"
|
40
|
+
end
|
41
|
+
|
42
|
+
extra_states = computed_states - states
|
43
|
+
|
44
|
+
unless extra_states.empty?
|
45
|
+
raise ExtraStates,
|
46
|
+
"#{extra_states} appeared in the transition map but were not explicitly declared as states"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_transitions(computed_transitions)
|
51
|
+
missing_transitions = transitions - computed_transitions
|
52
|
+
|
53
|
+
unless missing_transitions.empty?
|
54
|
+
raise MissingTransitions, "#{
|
55
|
+
missing_transitions
|
56
|
+
} is/are explicitly declared as transitions but do(es)n't appear in the transition map"
|
57
|
+
end
|
58
|
+
|
59
|
+
extra_transitions = computed_transitions - transitions
|
60
|
+
|
61
|
+
unless extra_transitions.empty?
|
62
|
+
raise ExtraTransitions,
|
63
|
+
"#{extra_transitions} appeared in the transition map but were not explicitly declared as transitions"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module Foobara::ThreadParent; end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Foobara
|
2
|
+
module ThreadParent
|
3
|
+
module ThreadClassExtensions
|
4
|
+
def new(...)
|
5
|
+
super.tap { |thread| thread.instance_variable_set("@foobara_parent", Thread.current) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Thread
|
12
|
+
class << self
|
13
|
+
prepend(Foobara::ThreadParent::ThreadClassExtensions)
|
14
|
+
|
15
|
+
def foobara_var_get(...)
|
16
|
+
Thread.current.foobara_var_get(...)
|
17
|
+
end
|
18
|
+
|
19
|
+
def foobara_var_set(...)
|
20
|
+
Thread.current.foobara_var_set(...)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :foobara_parent
|
25
|
+
|
26
|
+
# NOTE: because there's not a way to unset a thread variable, storing nil is used as deletion.
|
27
|
+
# this means that a thread local variable with nil can't have any semantic meaning and should be
|
28
|
+
# treated the same as if #thread_variable? had returned false.
|
29
|
+
def foobara_var_get(...)
|
30
|
+
value = thread_variable_get(...)
|
31
|
+
|
32
|
+
value.nil? ? foobara_parent&.foobara_var_get(...) : value
|
33
|
+
end
|
34
|
+
|
35
|
+
def foobara_var_set(...)
|
36
|
+
thread_variable_set(...)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
class << self
|
4
|
+
def reset_all
|
5
|
+
# TODO: this doesn't really belong here. I think we need to maybe call reset in reverse order?
|
6
|
+
Foobara::Domain::DomainModuleExtension.all.each do |domain|
|
7
|
+
var = "@foobara_type_builder"
|
8
|
+
|
9
|
+
if domain.instance_variable_defined?(var)
|
10
|
+
domain.remove_instance_variable(var)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Util.descendants(Error).each do |error_class|
|
15
|
+
if error_class.instance_variable_defined?(:@context_type)
|
16
|
+
error_class.remove_instance_variable(:@context_type)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
%w[
|
21
|
+
foobara_children
|
22
|
+
foobara_registry
|
23
|
+
foobara_type_builder
|
24
|
+
].each do |var_name|
|
25
|
+
var_name = "@#{var_name}"
|
26
|
+
|
27
|
+
# Don't we only have to do this for Foobara and not all of these??
|
28
|
+
[
|
29
|
+
Namespace.global,
|
30
|
+
Foobara::GlobalOrganization,
|
31
|
+
Foobara::GlobalDomain,
|
32
|
+
Domain,
|
33
|
+
Command,
|
34
|
+
Types::Type,
|
35
|
+
Value::Processor,
|
36
|
+
Error
|
37
|
+
].each do |klass|
|
38
|
+
klass.remove_instance_variable(var_name) if klass.instance_variable_defined?(var_name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if GlobalDomain.const_defined?(:Types, false)
|
43
|
+
GlobalDomain::Types.instance_variable_set(
|
44
|
+
:@foobara_lowercase_constants,
|
45
|
+
@original_foobara_lowercase_constants || []
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
@original_scoped.each do |scoped|
|
50
|
+
Namespace.global.foobara_register(scoped)
|
51
|
+
end
|
52
|
+
|
53
|
+
@original_children.each do |child|
|
54
|
+
Namespace.global.foobara_children << child
|
55
|
+
end
|
56
|
+
|
57
|
+
GlobalDomain.foobara_parent_namespace = GlobalOrganization
|
58
|
+
GlobalOrganization.foobara_register(GlobalDomain)
|
59
|
+
|
60
|
+
register_type_declaration(Handlers::RegisteredTypeDeclaration.new)
|
61
|
+
register_type_declaration(Handlers::ExtendRegisteredTypeDeclaration.new)
|
62
|
+
register_type_declaration(Handlers::ExtendArrayTypeDeclaration.new)
|
63
|
+
register_type_declaration(Handlers::ExtendAssociativeArrayTypeDeclaration.new)
|
64
|
+
register_type_declaration(Handlers::ExtendAttributesTypeDeclaration.new)
|
65
|
+
register_type_declaration(Handlers::ExtendTupleTypeDeclaration.new)
|
66
|
+
end
|
67
|
+
|
68
|
+
def install!
|
69
|
+
capture_current_namespaces
|
70
|
+
|
71
|
+
reset_all
|
72
|
+
|
73
|
+
Foobara::Error.include(ErrorExtension)
|
74
|
+
|
75
|
+
Value::Processor::Casting::CannotCastError.singleton_class.define_method :context_type_declaration do
|
76
|
+
{
|
77
|
+
cast_to: :duck,
|
78
|
+
value: :duck,
|
79
|
+
attribute_name: :symbol
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
Value::Processor::Selection::NoApplicableProcessorError.singleton_class.define_method(
|
84
|
+
:context_type_declaration
|
85
|
+
) do
|
86
|
+
{
|
87
|
+
processor_names: [:symbol],
|
88
|
+
value: :duck
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
Value::Processor::Selection::MoreThanOneApplicableProcessorError.singleton_class.define_method(
|
93
|
+
:context_type_declaration
|
94
|
+
) do
|
95
|
+
{
|
96
|
+
applicable_processor_names: [:symbol],
|
97
|
+
processor_names: [:symbol],
|
98
|
+
value: :duck
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
Value::DataError.singleton_class.define_method :context_type_declaration do
|
103
|
+
{
|
104
|
+
attribute_name: :symbol,
|
105
|
+
value: :duck
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def new_project_added(_project)
|
111
|
+
capture_current_namespaces
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def capture_current_namespaces
|
117
|
+
# TODO: this feels like the wrong place to do this but doing it here for now to make sure it's done when
|
118
|
+
# most important
|
119
|
+
@original_scoped = Namespace.global.foobara_registry.all_scoped.dup
|
120
|
+
@original_children = Namespace.global.foobara_children.dup
|
121
|
+
|
122
|
+
if GlobalDomain.const_defined?(:Types, false)
|
123
|
+
# :nocov:
|
124
|
+
@original_foobara_lowercase_constants =
|
125
|
+
GlobalDomain::Types.instance_variable_get(:@foobara_lowercase_constants).dup
|
126
|
+
# :nocov:
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Attributes
|
4
|
+
class << self
|
5
|
+
def merge(*type_declarations)
|
6
|
+
element_type_declarations = {}
|
7
|
+
required = []
|
8
|
+
defaults = {}
|
9
|
+
|
10
|
+
type_declarations.each do |declaration_data|
|
11
|
+
element_type_declarations.merge!(declaration_data[:element_type_declarations])
|
12
|
+
type_defaults = declaration_data[:defaults]
|
13
|
+
type_required = declaration_data[:required]
|
14
|
+
|
15
|
+
if type_defaults && !type_defaults.empty?
|
16
|
+
defaults.merge!(type_defaults)
|
17
|
+
end
|
18
|
+
|
19
|
+
if type_required && !type_required.empty?
|
20
|
+
required += type_required
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
{
|
25
|
+
type: "::attributes",
|
26
|
+
element_type_declarations:,
|
27
|
+
required:,
|
28
|
+
defaults:
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Foobara.require_project_file("type_declarations", "with_registries")
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module TypeDeclarations
|
5
|
+
class Desugarizer < Value::Transformer
|
6
|
+
include WithRegistries
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def requires_declaration_data?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def foobara_manifest(to_include:)
|
14
|
+
# :nocov:
|
15
|
+
super.merge(processor_type: :desugarizer)
|
16
|
+
# :nocov:
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def transform(value)
|
21
|
+
desugarize(value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Dsl
|
4
|
+
class NoTypeGivenError < StandardError; end
|
5
|
+
|
6
|
+
class BadAttributeError < StandardError
|
7
|
+
attr_accessor :attribute_name, :method_name
|
8
|
+
|
9
|
+
def initialize(attribute_name, method_name)
|
10
|
+
self.attribute_name = attribute_name
|
11
|
+
self.method_name = method_name
|
12
|
+
|
13
|
+
super("You probably did not mean to declare an attribute named \"#{attribute_name}\" " \
|
14
|
+
"but you tried to access .\"#{method_name}\" method on it. " \
|
15
|
+
"Return values of attribute declarations do not return anything meaningful.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Using this class as a proxy to explode if somebody accidentally tries to use the return value of an
|
20
|
+
# attribute declaration
|
21
|
+
# NOTE: when debugging stuff, it's helpful to comment out the inheritance from BasicObject
|
22
|
+
class AttributeCreated < BasicObject
|
23
|
+
def initialize(name)
|
24
|
+
@_name = name
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method_name, ...)
|
28
|
+
::Kernel.raise BadAttributeError.new(@_name, method_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def respond_to_missing?(...)
|
32
|
+
# :nocov:
|
33
|
+
false
|
34
|
+
# :nocov:
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# NOTE: when debugging stuff, it's helpful to comment out the inheritance from BasicObject
|
39
|
+
class Attributes < BasicObject
|
40
|
+
class << self
|
41
|
+
def to_declaration(&)
|
42
|
+
new._to_declaration(&)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_accessor :_method_missing_disabled
|
47
|
+
|
48
|
+
def _to_declaration(&)
|
49
|
+
instance_eval(&)
|
50
|
+
_prune_type_declaration
|
51
|
+
_type_declaration
|
52
|
+
end
|
53
|
+
|
54
|
+
def method_missing(attribute_name, *processor_symbols, **declaration, &block)
|
55
|
+
unless respond_to_missing?(attribute_name)
|
56
|
+
# :nocov:
|
57
|
+
return super
|
58
|
+
# :nocov:
|
59
|
+
end
|
60
|
+
|
61
|
+
_disable_method_missing do
|
62
|
+
declaration = declaration.dup
|
63
|
+
|
64
|
+
if block
|
65
|
+
# TODO: technically, current namespace might have an overridden :array type so instead we
|
66
|
+
# should lookup :array he to see if we get BuiltinTypes[:array] or not (or "::array" or not)
|
67
|
+
if processor_symbols.first == :array
|
68
|
+
type, *processor_symbols = processor_symbols
|
69
|
+
end
|
70
|
+
else
|
71
|
+
type, *processor_symbols = processor_symbols
|
72
|
+
|
73
|
+
unless type
|
74
|
+
if processor_symbols.empty? && !declaration.empty?
|
75
|
+
type = :attributes
|
76
|
+
declaration = { element_type_declarations: declaration }
|
77
|
+
else
|
78
|
+
::Kernel.raise NoTypeGivenError, "Expected a type but attribute #{attribute_name} was declared " \
|
79
|
+
"without a type. (Perhaps you didn't mean for #{attribute_name} " \
|
80
|
+
"to be an attribute?)"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
processor_symbols.each do |processor_symbol|
|
86
|
+
case processor_symbol
|
87
|
+
when ::String
|
88
|
+
description = processor_symbol
|
89
|
+
|
90
|
+
if declaration.key?(:description)
|
91
|
+
# :nocov:
|
92
|
+
::Kernel.raise ArgumentError, "Expected only one description but " \
|
93
|
+
"got #{description.inspect} and #{declaration[:description].inspect}"
|
94
|
+
# :nocov:
|
95
|
+
end
|
96
|
+
|
97
|
+
declaration[:description] = description
|
98
|
+
when ::Symbol
|
99
|
+
declaration[processor_symbol] = true
|
100
|
+
else
|
101
|
+
# :nocov:
|
102
|
+
::Kernel.raise ArgumentError, "expected a Symbol, got #{processor_symbol.inspect}"
|
103
|
+
# :nocov:
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if declaration.delete(:required)
|
108
|
+
_add_to_required(attribute_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
default = declaration.delete(:default)
|
112
|
+
|
113
|
+
if default
|
114
|
+
_add_to_defaults(attribute_name, default)
|
115
|
+
end
|
116
|
+
|
117
|
+
if declaration.empty? && !block
|
118
|
+
_add_attribute(attribute_name, type)
|
119
|
+
else
|
120
|
+
declaration = if block
|
121
|
+
attributes_declaration = Attributes.to_declaration(&block).merge(declaration)
|
122
|
+
|
123
|
+
if type == :array
|
124
|
+
{
|
125
|
+
type: :array,
|
126
|
+
element_type_declaration: attributes_declaration
|
127
|
+
}
|
128
|
+
else
|
129
|
+
attributes_declaration
|
130
|
+
end
|
131
|
+
else
|
132
|
+
declaration.merge(type:)
|
133
|
+
end
|
134
|
+
|
135
|
+
_add_attribute(attribute_name, declaration)
|
136
|
+
end
|
137
|
+
|
138
|
+
_type_declaration
|
139
|
+
|
140
|
+
AttributeCreated.new(attribute_name)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def respond_to_missing?(method_name, private = false)
|
145
|
+
!_method_missing_disabled || super
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def _disable_method_missing
|
151
|
+
old = _method_missing_disabled
|
152
|
+
|
153
|
+
begin
|
154
|
+
self._method_missing_disabled = true
|
155
|
+
yield
|
156
|
+
ensure
|
157
|
+
self._method_missing_disabled = old
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def _add_attribute(attribute_name, declaration)
|
162
|
+
_type_declaration[:element_type_declarations][attribute_name.to_sym] = declaration
|
163
|
+
end
|
164
|
+
|
165
|
+
def _add_to_required(attribute_name)
|
166
|
+
_type_declaration[:required] << attribute_name.to_sym
|
167
|
+
end
|
168
|
+
|
169
|
+
def _add_to_defaults(attribute_name, value)
|
170
|
+
_type_declaration[:defaults][attribute_name.to_sym] = value
|
171
|
+
end
|
172
|
+
|
173
|
+
def _prune_type_declaration
|
174
|
+
if _type_declaration[:required].empty?
|
175
|
+
_type_declaration.delete(:required)
|
176
|
+
end
|
177
|
+
|
178
|
+
if _type_declaration[:defaults].empty?
|
179
|
+
_type_declaration.delete(:defaults)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def _type_declaration
|
184
|
+
@_type_declaration ||= begin
|
185
|
+
sugar = {
|
186
|
+
type: "::attributes",
|
187
|
+
element_type_declarations: {},
|
188
|
+
required: [],
|
189
|
+
defaults: {}
|
190
|
+
}
|
191
|
+
|
192
|
+
handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
|
193
|
+
handler.desugarize(sugar)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
class << self
|
4
|
+
attr_accessor :validate_error_context_enabled
|
5
|
+
|
6
|
+
def validate_error_context_enabled?
|
7
|
+
validate_error_context_enabled
|
8
|
+
end
|
9
|
+
|
10
|
+
def with_validate_error_context_disabled
|
11
|
+
old_enabled = validate_error_context_enabled
|
12
|
+
|
13
|
+
begin
|
14
|
+
self.validate_error_context_enabled = false
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
self.validate_error_context_enabled = old_enabled
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
self.validate_error_context_enabled = true
|
23
|
+
|
24
|
+
module ErrorExtension
|
25
|
+
class NoContextTypeSetError < StandardError
|
26
|
+
def initialize
|
27
|
+
super("No context type declaration set. Either set it or mark the error as abstract")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
include Concern
|
32
|
+
# TODO: replace this with some kind of Foobara::TypeBuilder version
|
33
|
+
include WithRegistries
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
def context_type
|
37
|
+
@context_type ||= begin
|
38
|
+
Foobara::Domain.foobara_type_from_declaration(self, context_type_declaration)
|
39
|
+
rescue NoContextTypeSetError
|
40
|
+
if abstract?
|
41
|
+
nil
|
42
|
+
else
|
43
|
+
# :nocov:
|
44
|
+
raise
|
45
|
+
# :nocov:
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def context_type_declaration
|
51
|
+
# :nocov:
|
52
|
+
raise NoContextTypeSetError
|
53
|
+
# :nocov:
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(...)
|
58
|
+
super
|
59
|
+
|
60
|
+
validate_context!
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_context!
|
64
|
+
if TypeDeclarations.validate_error_context_enabled?
|
65
|
+
# TODO: we need to wrap this in a new error here to communicate what's going on a bit better
|
66
|
+
context_type.process_value!(context)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
foobara_delegate :context_type, :context_type_declaration, to: :class
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
2
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_associative_array_type_declaration")
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module TypeDeclarations
|
6
|
+
module Handlers
|
7
|
+
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
9
|
+
class ArrayDesugarizer < TypeDeclarations::Desugarizer
|
10
|
+
def applicable?(sugary_type_declaration)
|
11
|
+
sugary_type_declaration.is_a?(::Array) && sugary_type_declaration.size <= 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def desugarize(sugary_type_declaration)
|
15
|
+
strict_type_declaration = { type: :array, _desugarized: { type_absolutified: true } }
|
16
|
+
|
17
|
+
unless sugary_type_declaration.empty?
|
18
|
+
element_type_declaration = sugary_type_declaration.first
|
19
|
+
|
20
|
+
handler = type_declaration_handler_for(element_type_declaration)
|
21
|
+
|
22
|
+
strict_type_declaration[:element_type_declaration] = handler.desugarize(element_type_declaration)
|
23
|
+
end
|
24
|
+
|
25
|
+
strict_type_declaration
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
5
|
+
class ElementTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
6
|
+
def applicable?(sugary_type_declaration)
|
7
|
+
return false unless sugary_type_declaration.is_a?(::Hash)
|
8
|
+
return false unless Util.all_symbolizable_keys?(sugary_type_declaration)
|
9
|
+
|
10
|
+
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
11
|
+
|
12
|
+
return false unless sugary_type_declaration.key?(:type)
|
13
|
+
|
14
|
+
type_symbol = sugary_type_declaration[:type]
|
15
|
+
|
16
|
+
type_symbol == :array && sugary_type_declaration.key?(:element_type_declaration)
|
17
|
+
end
|
18
|
+
|
19
|
+
def desugarize(sugary_type_declaration)
|
20
|
+
sugar = sugary_type_declaration[:element_type_declaration]
|
21
|
+
|
22
|
+
handler = type_declaration_handler_for(sugar)
|
23
|
+
strict = handler.desugarize(sugar)
|
24
|
+
|
25
|
+
sugary_type_declaration[:element_type_declaration] = strict
|
26
|
+
|
27
|
+
sugary_type_declaration
|
28
|
+
end
|
29
|
+
|
30
|
+
def priority
|
31
|
+
Priority::LOW
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Foobara.require_project_file("type_declarations", "handlers/registered_type_declaration/to_type_transformer")
|
2
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_associative_array_type_declaration")
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module TypeDeclarations
|
6
|
+
module Handlers
|
7
|
+
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
|
+
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
9
|
+
def transform(strict_type_declaration)
|
10
|
+
super.tap do |type|
|
11
|
+
element_type_declaration = type.declaration_data[:element_type_declaration]
|
12
|
+
|
13
|
+
if element_type_declaration
|
14
|
+
type.element_type = type_for_declaration(element_type_declaration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|