foobara 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +5 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +10 -0
- data/DECISION_LOG.md +220 -0
- data/Guardfile +9 -0
- data/LICENSE-AGPL.txt +666 -0
- data/LICENSE.txt +4 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/concepts.md +153 -0
- data/projects/builtin_types/lib/foobara/builtin_types.rb +67 -0
- data/projects/builtin_types/src/README.md +140 -0
- data/projects/builtin_types/src/array/casters/arrayable.rb +22 -0
- data/projects/builtin_types/src/array/supported_processors/element_type_declaration.rb +41 -0
- data/projects/builtin_types/src/array/supported_validators/size.rb +43 -0
- data/projects/builtin_types/src/associative_array/casters/array.rb +22 -0
- data/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb +44 -0
- data/projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb +44 -0
- data/projects/builtin_types/src/atomic_duck.rb +6 -0
- data/projects/builtin_types/src/attributes/casters/array.rb +33 -0
- data/projects/builtin_types/src/attributes/casters/hash.rb +28 -0
- data/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb +89 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_defaults_from_element_types_to_root.rb +40 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/symbolize_defaults.rb +31 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/hash_with_symbolic_keys.rb +37 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/valid_attribute_names.rb +60 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults.rb +41 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_required_from_element_types_to_root.rb +55 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_of_symbols.rb +47 -0
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/array_with_valid_attribute_names.rb +54 -0
- data/projects/builtin_types/src/attributes/supported_validators/required.rb +51 -0
- data/projects/builtin_types/src/big_decimal/casters/integer.rb +21 -0
- data/projects/builtin_types/src/big_decimal/casters/string.rb +24 -0
- data/projects/builtin_types/src/boolean/casters/numeric.rb +21 -0
- data/projects/builtin_types/src/boolean/casters/string_or_symbol.rb +27 -0
- data/projects/builtin_types/src/builtin_types.rb +189 -0
- data/projects/builtin_types/src/date/casters/hash.rb +23 -0
- data/projects/builtin_types/src/date/casters/string.rb +40 -0
- data/projects/builtin_types/src/datetime/casters/date.rb +21 -0
- data/projects/builtin_types/src/datetime/casters/hash.rb +77 -0
- data/projects/builtin_types/src/datetime/casters/seconds_since_epoch.rb +21 -0
- data/projects/builtin_types/src/datetime/casters/string.rb +31 -0
- data/projects/builtin_types/src/duck/supported_casters/allow_nil.rb +38 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_desugarizer.rb +29 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_class_desugarizer.rb +31 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_symbol_desugarizer.rb +31 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb +43 -0
- data/projects/builtin_types/src/duck/supported_validators/instance_of.rb +42 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb +37 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb +41 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of.rb +41 -0
- data/projects/builtin_types/src/duck.rb +6 -0
- data/projects/builtin_types/src/duckture.rb +6 -0
- data/projects/builtin_types/src/email/transformers/downcase.rb +15 -0
- data/projects/builtin_types/src/email/validator_base.rb +94 -0
- data/projects/builtin_types/src/float/casters/integer.rb +21 -0
- data/projects/builtin_types/src/float/casters/string.rb +24 -0
- data/projects/builtin_types/src/integer/casters/string.rb +23 -0
- data/projects/builtin_types/src/number/supported_validators/max.rb +41 -0
- data/projects/builtin_types/src/number/supported_validators/min.rb +41 -0
- data/projects/builtin_types/src/string/casters/numeric.rb +21 -0
- data/projects/builtin_types/src/string/casters/symbol.rb +21 -0
- data/projects/builtin_types/src/string/supported_transformers/downcase.rb +11 -0
- data/projects/builtin_types/src/string/supported_validators/matches.rb +41 -0
- data/projects/builtin_types/src/string/supported_validators/max_length.rb +37 -0
- data/projects/builtin_types/src/symbol/casters/string.rb +21 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb +32 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb +50 -0
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb +59 -0
- data/projects/callback/lib/foobara/callback.rb +1 -0
- data/projects/callback/src/block/after.rb +10 -0
- data/projects/callback/src/block/around.rb +10 -0
- data/projects/callback/src/block/before.rb +10 -0
- data/projects/callback/src/block/concerns/block_parameter_not_allowed.rb +21 -0
- data/projects/callback/src/block/concerns/block_parameter_required.rb +21 -0
- data/projects/callback/src/block/concerns/keyword_argumentable_block.rb +31 -0
- data/projects/callback/src/block/concerns/single_argument_block.rb +22 -0
- data/projects/callback/src/block/concerns/type.rb +17 -0
- data/projects/callback/src/block/error.rb +10 -0
- data/projects/callback/src/block.rb +83 -0
- data/projects/callback/src/registry/base.rb +90 -0
- data/projects/callback/src/registry/chained_conditioned.rb +24 -0
- data/projects/callback/src/registry/chained_multiple_action.rb +24 -0
- data/projects/callback/src/registry/conditioned.rb +101 -0
- data/projects/callback/src/registry/multiple_action.rb +110 -0
- data/projects/callback/src/registry/single_action.rb +15 -0
- data/projects/callback/src/runner.rb +89 -0
- data/projects/callback/src/set.rb +56 -0
- data/projects/command/lib/foobara/command.rb +9 -0
- data/projects/command/src/command/entity_helpers.rb +145 -0
- data/projects/command/src/command.rb +36 -0
- data/projects/command/src/concerns/callbacks.rb +93 -0
- data/projects/command/src/concerns/description.rb +23 -0
- data/projects/command/src/concerns/domain_mappers.rb +35 -0
- data/projects/command/src/concerns/entities.rb +88 -0
- data/projects/command/src/concerns/errors.rb +181 -0
- data/projects/command/src/concerns/errors_type.rb +124 -0
- data/projects/command/src/concerns/inputs.rb +59 -0
- data/projects/command/src/concerns/inputs_type.rb +58 -0
- data/projects/command/src/concerns/namespace.rb +49 -0
- data/projects/command/src/concerns/reflection.rb +137 -0
- data/projects/command/src/concerns/result.rb +25 -0
- data/projects/command/src/concerns/result_type.rb +29 -0
- data/projects/command/src/concerns/runtime.rb +119 -0
- data/projects/command/src/concerns/state_machine.rb +12 -0
- data/projects/command/src/concerns/subcommands.rb +102 -0
- data/projects/command/src/concerns/transactions.rb +81 -0
- data/projects/command/src/state_machine.rb +57 -0
- data/projects/command/src/transformed_command.rb +459 -0
- data/projects/command_connectors/lib/foobara/command_connectors.rb +12 -0
- data/projects/command_connectors/src/command_connector.rb +401 -0
- data/projects/command_connectors/src/command_registry/allowed_rule.rb +29 -0
- data/projects/command_connectors/src/command_registry/exposed_command.rb +140 -0
- data/projects/command_connectors/src/command_registry/exposed_domain.rb +30 -0
- data/projects/command_connectors/src/command_registry/exposed_organization.rb +30 -0
- data/projects/command_connectors/src/command_registry.rb +257 -0
- data/projects/command_connectors/src/commands/describe.rb +36 -0
- data/projects/command_connectors/src/commands/list_commands.rb +51 -0
- data/projects/command_connectors/src/commands/ping.rb +21 -0
- data/projects/command_connectors/src/commands/query_git_commit_info.rb +81 -0
- data/projects/command_connectors/src/request.rb +99 -0
- data/projects/command_connectors/src/response.rb +17 -0
- data/projects/command_connectors/src/serializer.rb +25 -0
- data/projects/command_connectors/src/serializers/aggregate_serializer.rb +32 -0
- data/projects/command_connectors/src/serializers/atomic_serializer.rb +25 -0
- data/projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb +28 -0
- data/projects/command_connectors/src/serializers/errors_serializer.rb +18 -0
- data/projects/command_connectors/src/serializers/json_serializer.rb +20 -0
- data/projects/command_connectors/src/serializers/noop_serializer.rb +20 -0
- data/projects/command_connectors/src/serializers/record_store_serializer.rb +31 -0
- data/projects/command_connectors/src/serializers/success_serializer.rb +14 -0
- data/projects/command_connectors/src/serializers/yaml_serializer.rb +20 -0
- data/projects/command_connectors/src/transformers/auth_errors_transformer.rb +35 -0
- data/projects/command_connectors/src/transformers/load_aggregates_pre_commit_transformer.rb +36 -0
- data/projects/command_connectors_http/lib/foobara/command_connectors_http.rb +6 -0
- data/projects/command_connectors_http/src/http/commands/get_options.rb +16 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/command.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/domain.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/entity.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/error.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/model.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/organization.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor_class.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/root.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter/type.rb +14 -0
- data/projects/command_connectors_http/src/http/commands/help/presenter.rb +162 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/command.html.erb +11 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/domain.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/entity.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/error.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/model.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/organization.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/processor.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/processor_class.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/root.html.erb +3 -0
- data/projects/command_connectors_http/src/http/commands/help/templates/type.html.erb +1 -0
- data/projects/command_connectors_http/src/http/commands/help.rb +98 -0
- data/projects/command_connectors_http/src/http/request.rb +98 -0
- data/projects/command_connectors_http/src/http/response.rb +14 -0
- data/projects/command_connectors_http/src/http.rb +84 -0
- data/projects/common/lib/foobara/common.rb +11 -0
- data/projects/common/src/data_path.rb +272 -0
- data/projects/common/src/error.rb +215 -0
- data/projects/common/src/error_collection.rb +97 -0
- data/projects/common/src/error_key.rb +168 -0
- data/projects/common/src/outcome.rb +101 -0
- data/projects/common/src/possible_error.rb +80 -0
- data/projects/common/src/runtime_error.rb +24 -0
- data/projects/concerns/lib/foobara/concerns.rb +1 -0
- data/projects/concerns/src/concern.rb +93 -0
- data/projects/delegate/lib/foobara/delegate.rb +1 -0
- data/projects/delegate/src/extensions/module.rb +12 -0
- data/projects/domain/lib/foobara/domain.rb +25 -0
- data/projects/domain/src/domain.rb +65 -0
- data/projects/domain/src/domain_mapper/registry.rb +47 -0
- data/projects/domain/src/domain_mapper.rb +162 -0
- data/projects/domain/src/domain_module_extension.rb +510 -0
- data/projects/domain/src/extensions/foobara.rb +69 -0
- data/projects/domain/src/global_domain.rb +14 -0
- data/projects/domain/src/global_organization.rb +12 -0
- data/projects/domain/src/is_manifestable.rb +68 -0
- data/projects/domain/src/manifestable.rb +12 -0
- data/projects/domain/src/module_extension.rb +122 -0
- data/projects/domain/src/organization.rb +52 -0
- data/projects/domain/src/organization_module_extension.rb +50 -0
- data/projects/entity/lib/foobara/entity.rb +27 -0
- data/projects/entity/src/concerns/associations.rb +241 -0
- data/projects/entity/src/concerns/attributes.rb +170 -0
- data/projects/entity/src/concerns/callbacks.rb +97 -0
- data/projects/entity/src/concerns/initialization.rb +127 -0
- data/projects/entity/src/concerns/persistence.rb +142 -0
- data/projects/entity/src/concerns/primary_key.rb +43 -0
- data/projects/entity/src/concerns/queries.rb +96 -0
- data/projects/entity/src/concerns/reflection.rb +51 -0
- data/projects/entity/src/concerns/transactions.rb +31 -0
- data/projects/entity/src/concerns/types.rb +31 -0
- data/projects/entity/src/entity.rb +61 -0
- data/projects/entity/src/extensions/builtin_types/entity/casters/hash.rb +33 -0
- data/projects/entity/src/extensions/builtin_types/entity/validators/attributes_declaration.rb +32 -0
- data/projects/entity/src/extensions/builtin_types/entity.rb +6 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/attributes_handler_desugarizer.rb +14 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/hash_desugarizer.rb +43 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/model_class_desugarizer.rb +21 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/primary_key_desugarizer.rb +19 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb +64 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_is_symbol.rb +35 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_present.rb +27 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_references_attribute.rb +36 -0
- data/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration.rb +11 -0
- data/projects/entity/src/new_prepend.rb +21 -0
- data/projects/entity/src/not_found_error.rb +72 -0
- data/projects/enumerated/lib/foobara/enumerated.rb +1 -0
- data/projects/enumerated/src/accessors.rb +61 -0
- data/projects/enumerated/src/values.rb +121 -0
- data/projects/foobara/lib/foobara/all.rb +44 -0
- data/projects/in_memory_crud_driver/lib/foobara/in_memory_crud_driver.rb +3 -0
- data/projects/in_memory_crud_driver/src/in_memory.rb +10 -0
- data/projects/in_memory_crud_driver_minimal/lib/foobara/in_memory_crud_driver_minimal.rb +1 -0
- data/projects/in_memory_crud_driver_minimal/src/in_memory_minimal.rb +113 -0
- data/projects/manifest/lib/foobara/manifest.rb +4 -0
- data/projects/manifest/src/foobara/manifest/array.rb +13 -0
- data/projects/manifest/src/foobara/manifest/attributes.rb +40 -0
- data/projects/manifest/src/foobara/manifest/base_manifest.rb +161 -0
- data/projects/manifest/src/foobara/manifest/command.rb +59 -0
- data/projects/manifest/src/foobara/manifest/domain.rb +43 -0
- data/projects/manifest/src/foobara/manifest/entity.rb +35 -0
- data/projects/manifest/src/foobara/manifest/error.rb +33 -0
- data/projects/manifest/src/foobara/manifest/model.rb +43 -0
- data/projects/manifest/src/foobara/manifest/organization.rb +45 -0
- data/projects/manifest/src/foobara/manifest/possible_error.rb +30 -0
- data/projects/manifest/src/foobara/manifest/processor.rb +11 -0
- data/projects/manifest/src/foobara/manifest/processor_class.rb +11 -0
- data/projects/manifest/src/foobara/manifest/root_manifest.rb +112 -0
- data/projects/manifest/src/foobara/manifest/type.rb +86 -0
- data/projects/manifest/src/foobara/manifest/type_declaration.rb +117 -0
- data/projects/model/lib/foobara/model.rb +23 -0
- data/projects/model/src/concerns/reflection.rb +22 -0
- data/projects/model/src/concerns/types.rb +104 -0
- data/projects/model/src/extensions/builtin_types/model/casters/hash.rb +23 -0
- data/projects/model/src/extensions/builtin_types/model/transformers/mutable.rb +26 -0
- data/projects/model/src/extensions/builtin_types/model/validators/attributes_declaration.rb +33 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +24 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +32 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +119 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +57 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +21 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +37 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +25 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +46 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +28 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +27 -0
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +31 -0
- data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -0
- data/projects/model/src/model.rb +320 -0
- data/projects/monorepo/lib/foobara/monorepo/project.rb +52 -0
- data/projects/monorepo/lib/foobara/monorepo.rb +63 -0
- data/projects/namespace/lib/foobara/namespace.rb +4 -0
- data/projects/namespace/src/ambiguous_registry.rb +104 -0
- data/projects/namespace/src/base_registry.rb +66 -0
- data/projects/namespace/src/extensions/module.rb +5 -0
- data/projects/namespace/src/is_namespace.rb +352 -0
- data/projects/namespace/src/namespace/lookup_mode.rb +41 -0
- data/projects/namespace/src/namespace.rb +61 -0
- data/projects/namespace/src/namespace_helpers.rb +273 -0
- data/projects/namespace/src/prefixless_registry.rb +54 -0
- data/projects/namespace/src/scoped.rb +113 -0
- data/projects/namespace/src/unambiguous_registry.rb +65 -0
- data/projects/persistence/lib/foobara/persistence.rb +22 -0
- data/projects/persistence/src/entity_attributes_crud_driver.rb +241 -0
- data/projects/persistence/src/entity_base/table.rb +14 -0
- data/projects/persistence/src/entity_base/transaction/concerns/entity_callback_handling.rb +157 -0
- data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +83 -0
- data/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb +53 -0
- data/projects/persistence/src/entity_base/transaction/state_machine.rb +27 -0
- data/projects/persistence/src/entity_base/transaction.rb +163 -0
- data/projects/persistence/src/entity_base/transaction_table/concerns/queries.rb +42 -0
- data/projects/persistence/src/entity_base/transaction_table/concerns/record_tracking.rb +134 -0
- data/projects/persistence/src/entity_base/transaction_table.rb +620 -0
- data/projects/persistence/src/entity_base.rb +114 -0
- data/projects/persistence/src/persistence.rb +172 -0
- data/projects/state_machine/lib/foobara/state_machine.rb +1 -0
- data/projects/state_machine/src/callbacks.rb +158 -0
- data/projects/state_machine/src/log_entry.rb +13 -0
- data/projects/state_machine/src/state_machine.rb +91 -0
- data/projects/state_machine/src/sugar.rb +125 -0
- data/projects/state_machine/src/transition_log.rb +19 -0
- data/projects/state_machine/src/validations.rb +69 -0
- data/projects/thread_parent/lib/foobara/thread_parent.rb +1 -0
- data/projects/thread_parent/src/thread_parent.rb +38 -0
- data/projects/type_declarations/lib/foobara/type_declarations.rb +131 -0
- data/projects/type_declarations/src/attributes.rb +34 -0
- data/projects/type_declarations/src/caster.rb +7 -0
- data/projects/type_declarations/src/desugarizer.rb +25 -0
- data/projects/type_declarations/src/dsl/attributes.rb +199 -0
- data/projects/type_declarations/src/element_processor.rb +7 -0
- data/projects/type_declarations/src/error_extension.rb +73 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +31 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +37 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +22 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +36 -0
- data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +14 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +28 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +20 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +25 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +34 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +60 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +21 -0
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +16 -0
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +75 -0
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +23 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +30 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +24 -0
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +13 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +29 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +65 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +32 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +39 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +26 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +28 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +24 -0
- data/projects/type_declarations/src/handlers/registered_type_declaration.rb +26 -0
- data/projects/type_declarations/src/processor.rb +7 -0
- data/projects/type_declarations/src/to_type_transformer.rb +11 -0
- data/projects/type_declarations/src/transformer.rb +7 -0
- data/projects/type_declarations/src/type_builder.rb +112 -0
- data/projects/type_declarations/src/type_declaration_error.rb +9 -0
- data/projects/type_declarations/src/type_declaration_handler.rb +120 -0
- data/projects/type_declarations/src/type_declaration_handler_registry.rb +27 -0
- data/projects/type_declarations/src/type_declaration_validator.rb +19 -0
- data/projects/type_declarations/src/type_declarations.rb +128 -0
- data/projects/type_declarations/src/typed_transformer.rb +89 -0
- data/projects/type_declarations/src/validator.rb +7 -0
- data/projects/type_declarations/src/with_registries.rb +41 -0
- data/projects/types/lib/foobara/types.rb +11 -0
- data/projects/types/src/element_processor.rb +7 -0
- data/projects/types/src/extensions/error.rb +32 -0
- data/projects/types/src/type/concerns/reflection.rb +79 -0
- data/projects/types/src/type/concerns/supported_processor_registration.rb +56 -0
- data/projects/types/src/type.rb +375 -0
- data/projects/types/src/types.rb +4 -0
- data/projects/value/lib/foobara/value.rb +7 -0
- data/projects/value/src/caster.rb +84 -0
- data/projects/value/src/data_error.rb +27 -0
- data/projects/value/src/processor/casting.rb +123 -0
- data/projects/value/src/processor/multi.rb +63 -0
- data/projects/value/src/processor/pipeline.rb +27 -0
- data/projects/value/src/processor/runner.rb +38 -0
- data/projects/value/src/processor/selection.rb +90 -0
- data/projects/value/src/processor.rb +358 -0
- data/projects/value/src/transformer.rb +84 -0
- data/projects/value/src/validator.rb +53 -0
- data/projects/version/lib/foobara/version.rb +4 -0
- data/projects/version/src/version.rb +5 -0
- data/projects/weak_object_set/lib/foobara/weak_object_set.rb +3 -0
- data/projects/weak_object_set/src/weak_object_set.rb +163 -0
- metadata +445 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require_relative "array_desugarizer"
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
7
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
|
8
|
+
class TypeSetToArrayDesugarizer < ArrayDesugarizer
|
|
9
|
+
def applicable?(sugary_type_declaration)
|
|
10
|
+
if sugary_type_declaration.is_a?(::Hash) && sugary_type_declaration.key?(:type)
|
|
11
|
+
extra_keys = sugary_type_declaration.keys - %i[type description]
|
|
12
|
+
|
|
13
|
+
return false if extra_keys.any?
|
|
14
|
+
|
|
15
|
+
type = sugary_type_declaration[:type]
|
|
16
|
+
|
|
17
|
+
if type.is_a?(::Array)
|
|
18
|
+
super(type)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def desugarize(sugary_type_declaration)
|
|
24
|
+
strict_type_declaration = super(sugary_type_declaration[:type])
|
|
25
|
+
|
|
26
|
+
if sugary_type_declaration.key?(:description)
|
|
27
|
+
strict_type_declaration[:description] = sugary_type_declaration[:description]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
strict_type_declaration
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
module Handlers
|
|
4
|
+
# Hmmmm... this inheritance feels backwards
|
|
5
|
+
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
6
|
+
def applicable?(sugary_type_declaration)
|
|
7
|
+
strictish_type_declaration = desugarize(sugary_type_declaration)
|
|
8
|
+
|
|
9
|
+
strictish_type_declaration.is_a?(::Hash) && strictish_type_declaration[:type] == :array
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Foobara.require_project_file(
|
|
2
|
+
"type_declarations",
|
|
3
|
+
"handlers/extend_registered_type_declaration/to_type_transformer"
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
module Foobara
|
|
7
|
+
module TypeDeclarations
|
|
8
|
+
module Handlers
|
|
9
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
|
10
|
+
class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
|
|
11
|
+
def transform(strict_type_declaration)
|
|
12
|
+
super.tap do |type|
|
|
13
|
+
key_type_declaration = type.declaration_data[:key_type_declaration]
|
|
14
|
+
value_type_declaration = type.declaration_data[:value_type_declaration]
|
|
15
|
+
|
|
16
|
+
if key_type_declaration || value_type_declaration
|
|
17
|
+
type.element_types = [
|
|
18
|
+
type_for_declaration(key_type_declaration || :duck),
|
|
19
|
+
type_for_declaration(value_type_declaration || :duck)
|
|
20
|
+
]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_registered_type_declaration")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
|
7
|
+
def applicable?(sugary_type_declaration)
|
|
8
|
+
strictish_type_declaration = desugarize(sugary_type_declaration)
|
|
9
|
+
|
|
10
|
+
strictish_type_declaration.is_a?(::Hash) && strictish_type_declaration[:type] == :associative_array
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# TODO: do we really need this? Isn't this the default?
|
|
14
|
+
def priority
|
|
15
|
+
Priority::LOW
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_attributes_type_declaration/hash_desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
7
|
+
class DslDesugarizer < TypeDeclarations::Desugarizer
|
|
8
|
+
def applicable?(sugary_type_declaration)
|
|
9
|
+
sugary_type_declaration.is_a?(::Proc)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def desugarize(block)
|
|
13
|
+
Foobara::TypeDeclarations::Dsl::Attributes.to_declaration(&block)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def priority
|
|
17
|
+
# TODO: need a way to express that we must run after/before other processors so that we could just say
|
|
18
|
+
# we are higher priority than the HashDesugarizer...
|
|
19
|
+
Priority::HIGH - 1
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_associative_array_type_declaration")
|
|
3
|
+
Foobara.require_project_file("type_declarations", "handlers/extend_attributes_type_declaration/hash_desugarizer")
|
|
4
|
+
|
|
5
|
+
module Foobara
|
|
6
|
+
module TypeDeclarations
|
|
7
|
+
module Handlers
|
|
8
|
+
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
9
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
|
10
|
+
class ElementTypeDeclarationsDesugarizer < HashDesugarizer
|
|
11
|
+
def desugarize(sugary_type_declaration)
|
|
12
|
+
sugary_type_declaration = sugary_type_declaration.dup
|
|
13
|
+
|
|
14
|
+
sugary_type_declaration[:element_type_declarations] =
|
|
15
|
+
sugary_type_declaration[:element_type_declarations].to_h do |attribute_name, element_type_declaration|
|
|
16
|
+
if attribute_name != :_desugarized
|
|
17
|
+
handler = type_declaration_handler_for(element_type_declaration)
|
|
18
|
+
element_type_declaration = handler.desugarize(element_type_declaration)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
[attribute_name, element_type_declaration]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
sugary_type_declaration
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def priority
|
|
28
|
+
Priority::LOW
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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 ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
8
|
+
class HashDesugarizer < TypeDeclarations::Desugarizer
|
|
9
|
+
def applicable?(sugary_type_declaration)
|
|
10
|
+
return false unless sugary_type_declaration.is_a?(::Hash)
|
|
11
|
+
return false unless Util.all_symbolizable_keys?(sugary_type_declaration)
|
|
12
|
+
|
|
13
|
+
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
|
14
|
+
|
|
15
|
+
return true unless sugary_type_declaration.key?(:type)
|
|
16
|
+
|
|
17
|
+
type_symbol = sugary_type_declaration[:type]
|
|
18
|
+
|
|
19
|
+
if [:attributes, "attributes"].include?(type_symbol)
|
|
20
|
+
Util.all_symbolizable_keys?(sugary_type_declaration[:element_type_declarations])
|
|
21
|
+
elsif type_symbol.is_a?(::Symbol)
|
|
22
|
+
# Why is this done?
|
|
23
|
+
!type_registered?(type_symbol)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def desugarize(sugary_type_declaration)
|
|
28
|
+
sugary_type_declaration = Util.deep_dup(sugary_type_declaration)
|
|
29
|
+
|
|
30
|
+
Util.symbolize_keys!(sugary_type_declaration)
|
|
31
|
+
|
|
32
|
+
unless strictish_type_declaration?(sugary_type_declaration)
|
|
33
|
+
sugary_type_declaration = {
|
|
34
|
+
type: :attributes,
|
|
35
|
+
_desugarized: { type_absolutified: true },
|
|
36
|
+
element_type_declarations: sugary_type_declaration
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
Util.symbolize_keys!(sugary_type_declaration[:element_type_declarations])
|
|
42
|
+
|
|
43
|
+
sugary_type_declaration
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def priority
|
|
47
|
+
Priority::HIGH
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def strictish_type_declaration?(hash)
|
|
53
|
+
keys = hash.keys.map(&:to_sym)
|
|
54
|
+
keys.include?(:type) && keys.include?(:element_type_declarations)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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 ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
8
|
+
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
|
9
|
+
def transform(strict_type_declaration)
|
|
10
|
+
super.tap do |type|
|
|
11
|
+
type_declarations = type.declaration_data[:element_type_declarations]
|
|
12
|
+
type.element_types = type_declarations.transform_values do |attribute_declaration|
|
|
13
|
+
type_for_declaration(attribute_declaration)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
module Handlers
|
|
4
|
+
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
5
|
+
def applicable?(sugary_type_declaration)
|
|
6
|
+
strictish_type_declaration = desugarize(sugary_type_declaration)
|
|
7
|
+
strictish_type_declaration.is_a?(::Hash) && strictish_type_declaration[:type] == :attributes
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def priority
|
|
11
|
+
Priority::LOW
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
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 ExtendRegisteredTypeDeclaration < RegisteredTypeDeclaration
|
|
8
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
|
9
|
+
class ToTypeTransformer < RegisteredTypeDeclaration::ToTypeTransformer
|
|
10
|
+
def transform(strict_type_declaration)
|
|
11
|
+
# TODO: maybe cache this stuff??
|
|
12
|
+
base_type = super
|
|
13
|
+
|
|
14
|
+
casters = []
|
|
15
|
+
transformers = []
|
|
16
|
+
validators = []
|
|
17
|
+
element_processors = []
|
|
18
|
+
|
|
19
|
+
additional_processors_to_apply = strict_type_declaration.except(*non_processor_keys)
|
|
20
|
+
|
|
21
|
+
# TODO: validate the name
|
|
22
|
+
additional_processors_to_apply.each_pair do |processor_symbol, declaration_data|
|
|
23
|
+
processor_class = base_type.find_supported_processor_class(processor_symbol)
|
|
24
|
+
processor = processor_class.new_with_agnostic_args(
|
|
25
|
+
declaration_data:,
|
|
26
|
+
parent_declaration_data: strict_type_declaration
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
category = case processor
|
|
30
|
+
when Value::Caster
|
|
31
|
+
casters
|
|
32
|
+
when Value::Validator
|
|
33
|
+
validators
|
|
34
|
+
when Value::Transformer
|
|
35
|
+
transformers
|
|
36
|
+
when Types::ElementProcessor
|
|
37
|
+
element_processors
|
|
38
|
+
else
|
|
39
|
+
# TODO: add validator that these are all fine so we don't have to bother here...
|
|
40
|
+
# :nocov:
|
|
41
|
+
raise "Not sure where to put #{processor}"
|
|
42
|
+
# :nocov:
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
category << processor
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Types::Type.new(
|
|
49
|
+
strict_type_declaration,
|
|
50
|
+
base_type:,
|
|
51
|
+
# description: strict_type_declaration.is_a?(::Hash) && strict_type_declaration[:description],
|
|
52
|
+
description: strict_type_declaration[:description],
|
|
53
|
+
casters:,
|
|
54
|
+
transformers:,
|
|
55
|
+
validators:,
|
|
56
|
+
element_processors:,
|
|
57
|
+
# TODO: can't we just set this to [] here??
|
|
58
|
+
target_classes: target_classes(strict_type_declaration),
|
|
59
|
+
name: type_name(strict_type_declaration)
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# TODO: test that registering a custom type sets its name
|
|
64
|
+
def type_name(strict_type_declaration)
|
|
65
|
+
"Anonymous #{strict_type_declaration[:type]} extension"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def non_processor_keys
|
|
69
|
+
%i[type _desugarized description]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "handlers/registered_type_declaration")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class ExtendRegisteredTypeDeclaration < RegisteredTypeDeclaration
|
|
7
|
+
def applicable?(sugary_type_declaration)
|
|
8
|
+
strict_type_declaration = desugarize(sugary_type_declaration)
|
|
9
|
+
|
|
10
|
+
return false unless strict_type_declaration.is_a?(::Hash)
|
|
11
|
+
# if there's no processors to extend the existing type with, then we don't handle that here
|
|
12
|
+
return false if strict_type_declaration.keys == [:type]
|
|
13
|
+
|
|
14
|
+
super(strict_type_declaration.slice(:type))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def priority
|
|
18
|
+
Priority::LOWEST
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 ExtendTupleTypeDeclaration < 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
|
+
element_type_declarations = sugary_type_declaration.map do |element_type_declaration|
|
|
16
|
+
handler = type_declaration_handler_for(element_type_declaration)
|
|
17
|
+
|
|
18
|
+
handler.desugarize(element_type_declaration)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
{
|
|
22
|
+
type: :tuple,
|
|
23
|
+
element_type_declarations:
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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 ExtendTupleTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
8
|
+
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
|
9
|
+
def transform(strict_type_declaration)
|
|
10
|
+
super.tap do |type|
|
|
11
|
+
element_type_declarations = type.declaration_data[:element_type_declarations]
|
|
12
|
+
|
|
13
|
+
if element_type_declarations && !element_type_declarations.empty?
|
|
14
|
+
type.element_types = element_type_declarations.map do |element_type_declaration|
|
|
15
|
+
type_for_declaration(element_type_declaration)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
module TypeDeclarations
|
|
3
|
+
module Handlers
|
|
4
|
+
class ExtendTupleTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
|
5
|
+
def applicable?(sugary_type_declaration)
|
|
6
|
+
strictish_type_declaration = desugarize(sugary_type_declaration)
|
|
7
|
+
|
|
8
|
+
strictish_type_declaration.is_a?(::Hash) && strictish_type_declaration[:type] == :tuple
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# type_symbol is basically just a flag that lets us know that type is fully qualified.
|
|
8
|
+
# rather hacky but other potential workarounds seemed gnarlier
|
|
9
|
+
class DesugarizerMetadataCleanupDesugarizer < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(strict_type_declaration)
|
|
11
|
+
strict_type_declaration.is_a?(::Hash)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def desugarize(strict_type_declaration)
|
|
15
|
+
strict_type_declaration = strict_type_declaration.dup
|
|
16
|
+
|
|
17
|
+
strict_type_declaration.delete(:_desugarized)
|
|
18
|
+
|
|
19
|
+
strict_type_declaration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def priority
|
|
23
|
+
Priority::LOWEST + 100
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# type_symbol is basically just a flag that lets us know that type is fully qualified.
|
|
8
|
+
# rather hacky but other potential workarounds seemed gnarlier
|
|
9
|
+
class ShortTypeNameDesugarizer < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(sugary_type_declaration)
|
|
11
|
+
return false if TypeDeclarations.strict_stringified? || TypeDeclarations.strict?
|
|
12
|
+
|
|
13
|
+
sugary_type_declaration = sugary_type_declaration.dup
|
|
14
|
+
|
|
15
|
+
return false unless sugary_type_declaration.is_a?(::Hash)
|
|
16
|
+
|
|
17
|
+
sugary_type_declaration = normalize_type(sugary_type_declaration)
|
|
18
|
+
|
|
19
|
+
if sugary_type_declaration.key?(:type) &&
|
|
20
|
+
!sugary_type_declaration.dig(:_desugarized, :type_absolutified)
|
|
21
|
+
type_symbol = sugary_type_declaration[:type]
|
|
22
|
+
|
|
23
|
+
(type_symbol.is_a?(::Symbol) || type_symbol.is_a?(::String)) && type_registered?(type_symbol)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def desugarize(sugary_type_declaration)
|
|
28
|
+
sugary_type_declaration = normalize_type(sugary_type_declaration)
|
|
29
|
+
|
|
30
|
+
type_symbol = sugary_type_declaration[:type]
|
|
31
|
+
type = lookup_type!(type_symbol)
|
|
32
|
+
|
|
33
|
+
desugarized = sugary_type_declaration[:_desugarized] || {}
|
|
34
|
+
desugarized[:type_absolutified] = true
|
|
35
|
+
# TODO: just use the symbol and nothing else??
|
|
36
|
+
# maybe confusing in languages with no distinction between symbol and string?
|
|
37
|
+
sugary_type_declaration.merge(type: type.full_type_symbol, _desugarized: desugarized)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# TODO: clean this up in a different desugarizer so we don't have to think about it here
|
|
41
|
+
def normalize_type(sugary_type_declaration)
|
|
42
|
+
if sugary_type_declaration.key?("type") && !sugary_type_declaration.key?(:type)
|
|
43
|
+
if Util.all_symbolizable_keys?(sugary_type_declaration)
|
|
44
|
+
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
|
45
|
+
type_symbol = sugary_type_declaration[:type]
|
|
46
|
+
|
|
47
|
+
if type_symbol.is_a?(::String)
|
|
48
|
+
sugary_type_declaration[:type] = type_symbol.to_sym
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
sugary_type_declaration = sugary_type_declaration.dup
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
sugary_type_declaration
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def priority
|
|
59
|
+
Priority::FIRST + 2
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# type_symbol is basically just a flag that lets us know that type is fully qualified.
|
|
8
|
+
# rather hacky but other potential workarounds seemed gnarlier
|
|
9
|
+
class StrictDesugarizer < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(strict_type_declaration)
|
|
11
|
+
# TODO: we shouldn't have to check if this is a hash. This means some other desugarizer is unnecessarily
|
|
12
|
+
# processing a type declaration as if it were sugary. Find and fix that to speed this up a tiny bit.
|
|
13
|
+
return false unless strict_type_declaration.is_a?(::Hash) && TypeDeclarations.strict?
|
|
14
|
+
|
|
15
|
+
!strict_type_declaration.dig(:_desugarized, :type_absolutified)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def desugarize(strict_type_declaration)
|
|
19
|
+
strict_type_declaration = Util.symbolize_keys(strict_type_declaration)
|
|
20
|
+
desugarized = strict_type_declaration[:_desugarized] || {}
|
|
21
|
+
desugarized[:type_absolutified] = true
|
|
22
|
+
strict_type_declaration.merge(_desugarized: desugarized)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def priority
|
|
26
|
+
Priority::FIRST
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# type_symbol is basically just a flag that lets us know that type is fully qualified.
|
|
8
|
+
# rather hacky but other potential workarounds seemed gnarlier
|
|
9
|
+
class StrictStringifiedDesugarizer < TypeDeclarations::Desugarizer
|
|
10
|
+
def applicable?(sugary_type_declaration)
|
|
11
|
+
# TODO: we shouldn't have to check if this is a hash. This means some other desugarizer is unnecessarily
|
|
12
|
+
# processing a type declaration as if it were sugary. Find and fix that to speed this up a tiny bit.
|
|
13
|
+
return false unless sugary_type_declaration.is_a?(::Hash) && TypeDeclarations.strict_stringified?
|
|
14
|
+
|
|
15
|
+
!sugary_type_declaration.dig(:_desugarized, :type_absolutified)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def desugarize(sugary_type_declaration)
|
|
19
|
+
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
|
20
|
+
type_symbol = sugary_type_declaration[:type]
|
|
21
|
+
|
|
22
|
+
type = Foobara.foobara_root_namespace.foobara_lookup_type!(type_symbol,
|
|
23
|
+
mode: Namespace::LookupMode::ABSOLUTE)
|
|
24
|
+
|
|
25
|
+
type_symbol = type.full_type_symbol
|
|
26
|
+
|
|
27
|
+
desugarized = sugary_type_declaration[:_desugarized] || {}
|
|
28
|
+
desugarized[:type_absolutified] = true
|
|
29
|
+
sugary_type_declaration.merge(_desugarized: desugarized, type: type_symbol)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def priority
|
|
33
|
+
Priority::FIRST
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "desugarizer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# TODO: make a quick way to convert a couple simple procs into a transformer
|
|
8
|
+
class SymbolDesugarizer < TypeDeclarations::Desugarizer
|
|
9
|
+
def applicable?(sugary_type_declaration)
|
|
10
|
+
sugary_type_declaration.is_a?(Symbol) && type_registered?(sugary_type_declaration)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def desugarize(symbol)
|
|
14
|
+
# TODO: just use the symbol and nothing else??
|
|
15
|
+
# maybe confusing in languages with no distinction between symbol and string?
|
|
16
|
+
{ type: symbol }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def priority
|
|
20
|
+
Priority::FIRST
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Foobara.require_project_file("type_declarations", "to_type_transformer")
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module TypeDeclarations
|
|
5
|
+
module Handlers
|
|
6
|
+
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
|
7
|
+
# TODO: seems like we have more base classes than we need
|
|
8
|
+
class ToTypeTransformer < TypeDeclarations::ToTypeTransformer
|
|
9
|
+
def transform(strict_type_declaration)
|
|
10
|
+
registered_type(strict_type_declaration)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def type_symbol(strict_type_declaration)
|
|
14
|
+
strict_type_declaration[:type]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def registered_type(strict_type_declaration)
|
|
18
|
+
lookup_absolute_type!(type_symbol(strict_type_declaration), mode: Namespace::LookupMode::ABSOLUTE)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def target_classes(strict_type_declaration)
|
|
22
|
+
registered_type(strict_type_declaration).target_classes
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|