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,97 @@
|
|
1
|
+
module Foobara
|
2
|
+
# TODO: inherit array instead of delegating
|
3
|
+
class ErrorCollection
|
4
|
+
class ErrorAlreadySetError < StandardError; end
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def to_h(errors)
|
8
|
+
new.tap do |collection|
|
9
|
+
collection.add_errors(errors)
|
10
|
+
end.to_h
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :error_array
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@error_array = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def success?
|
21
|
+
empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_errors?
|
25
|
+
!empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
foobara_delegate :empty?, :partition, :size, to: :error_array
|
29
|
+
|
30
|
+
def errors
|
31
|
+
error_array
|
32
|
+
end
|
33
|
+
|
34
|
+
def each_error(&)
|
35
|
+
error_array.each(&)
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_error?(error)
|
39
|
+
unless error.is_a?(Error)
|
40
|
+
# :nocov:
|
41
|
+
raise ArgumentError, "Can only check if an Error instance is in the collection"
|
42
|
+
# :nocov:
|
43
|
+
end
|
44
|
+
|
45
|
+
error_array.include?(error)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_error(error_or_collection_or_error_hash)
|
49
|
+
error = case error_or_collection_or_error_hash
|
50
|
+
when Error
|
51
|
+
error_or_collection_or_error_hash
|
52
|
+
when ErrorCollection
|
53
|
+
return add_errors(error_or_collection_or_error_hash.errors)
|
54
|
+
when Hash
|
55
|
+
if error_or_collection_or_error_hash.key?(:symbol) &&
|
56
|
+
error_or_collection_or_error_hash.key?(:message)
|
57
|
+
Error.new(**error_or_collection_or_error_hash)
|
58
|
+
else
|
59
|
+
# :nocov:
|
60
|
+
raise ArgumentError,
|
61
|
+
"if passing a hash of error args it must include symbol and message at least"
|
62
|
+
# :nocov:
|
63
|
+
end
|
64
|
+
else
|
65
|
+
# :nocov:
|
66
|
+
raise ArgumentError, "Not sure how to convert #{args.inspect} into an error. " \
|
67
|
+
"Can handle a hash of error " \
|
68
|
+
"args or 3 arguments for symbol, message, and context, or, of course, an Error"
|
69
|
+
# :nocov:
|
70
|
+
end
|
71
|
+
|
72
|
+
if has_error?(error)
|
73
|
+
raise ErrorAlreadySetError, "cannot set #{error} more than once"
|
74
|
+
end
|
75
|
+
|
76
|
+
error_array << error
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_errors(errors)
|
80
|
+
Util.array(errors).each { |error| add_error(error) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_h
|
84
|
+
error_array.to_h do |error|
|
85
|
+
[error.key, error.to_h]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_sentence
|
90
|
+
Util.to_sentence(error_array.map(&:message))
|
91
|
+
end
|
92
|
+
|
93
|
+
def keys
|
94
|
+
error_array.map(&:key)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Foobara
|
2
|
+
# TODO: path's have use outside of errors. Make this more general.
|
3
|
+
class ErrorKey
|
4
|
+
# TODO: use this wherever it makes sense
|
5
|
+
EMPTY_PATH = [].freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def to_s_type(key)
|
9
|
+
unless key.is_a?(ErrorKey)
|
10
|
+
key = parse(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
key.to_s_type
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepend_path(key, *)
|
17
|
+
if key.is_a?(ErrorKey)
|
18
|
+
key.prepend_path(*).to_s
|
19
|
+
else
|
20
|
+
key = parse(key)
|
21
|
+
key.prepend_path!(*).to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepend_runtime_path(key, prepend_part)
|
26
|
+
if key.is_a?(ErrorKey)
|
27
|
+
key.prepend_runtime_path(prepend_part).to_s
|
28
|
+
else
|
29
|
+
key = parse(key)
|
30
|
+
key.prepend_runtime_path!(prepend_part).to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# key contains.......
|
35
|
+
# a;b;c;d.e.f.g.h
|
36
|
+
# Then a, b, c is the runtime path and d is the category and e,f,g is the data path and h is the symbol
|
37
|
+
def parse(key_string)
|
38
|
+
*runtime_path, key_string = key_string.to_s.split(">")
|
39
|
+
category, *path, symbol = key_string.split(".")
|
40
|
+
|
41
|
+
new(category:, path:, symbol:, runtime_path:)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_h(key_string)
|
45
|
+
parse(key_string).to_h
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_reader :category, :symbol, :path, :runtime_path
|
50
|
+
|
51
|
+
# TODO: accept error_class instead of symbol/category??
|
52
|
+
def initialize(symbol: nil, category: nil, path: EMPTY_PATH, runtime_path: EMPTY_PATH)
|
53
|
+
self.category = symbolize(category)
|
54
|
+
self.symbol = symbolize(symbol)
|
55
|
+
self.path = symbolize(path)
|
56
|
+
self.runtime_path = symbolize(runtime_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def symbol=(symbol)
|
60
|
+
@symbol = symbolize(symbol)
|
61
|
+
end
|
62
|
+
|
63
|
+
def category=(category)
|
64
|
+
@category = symbolize(category)
|
65
|
+
end
|
66
|
+
|
67
|
+
def path=(path)
|
68
|
+
@path = symbolize_all(path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def runtime_path=(runtime_path)
|
72
|
+
@runtime_path = symbolize_all(runtime_path)
|
73
|
+
end
|
74
|
+
|
75
|
+
def prepend_path!(*prepend_parts)
|
76
|
+
if prepend_parts.size == 1
|
77
|
+
arg = prepend_parts.first
|
78
|
+
|
79
|
+
if arg.is_a?(Array)
|
80
|
+
prepend_parts = arg
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
self.path = [*prepend_parts, *path]
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def prepend_path(*)
|
89
|
+
dup.tap do |key|
|
90
|
+
key.prepend_path!(*)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def prepend_runtime_path!(prepend_parts)
|
95
|
+
self.runtime_path = [*prepend_parts, *runtime_path]
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def prepend_runtime_path(prepend_parts)
|
100
|
+
dup.tap do |key|
|
101
|
+
key.runtime_path = [*prepend_parts, *runtime_path]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
INDEX_VALUE = /\A\d+\z/
|
106
|
+
|
107
|
+
def to_s(convert_to_type: false)
|
108
|
+
path = self.path
|
109
|
+
|
110
|
+
if convert_to_type
|
111
|
+
path = path.map do |path_part|
|
112
|
+
path_part =~ INDEX_VALUE ? :"#" : path_part
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
[
|
117
|
+
*runtime_path,
|
118
|
+
[category, *path, symbol].join(".")
|
119
|
+
].join(">")
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_sym(**)
|
123
|
+
to_s(**).to_sym
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_s_type
|
127
|
+
to_s(convert_to_type: true)
|
128
|
+
end
|
129
|
+
|
130
|
+
def to_h
|
131
|
+
{
|
132
|
+
path:,
|
133
|
+
runtime_path:,
|
134
|
+
category:,
|
135
|
+
symbol:
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def symbolize_all(key_parts)
|
142
|
+
symbolize(Util.array(key_parts))
|
143
|
+
end
|
144
|
+
|
145
|
+
def symbolize(key_parts)
|
146
|
+
return nil if key_parts.nil?
|
147
|
+
|
148
|
+
case key_parts
|
149
|
+
when Array
|
150
|
+
key_parts.map do |key_part|
|
151
|
+
symbolize(key_part)
|
152
|
+
end
|
153
|
+
when Symbol, Integer
|
154
|
+
key_parts
|
155
|
+
when String
|
156
|
+
if key_parts.empty?
|
157
|
+
nil
|
158
|
+
else
|
159
|
+
key_parts.to_sym
|
160
|
+
end
|
161
|
+
else
|
162
|
+
# :nocov:
|
163
|
+
raise ArgumentError, "expected nil, a symbol, or a string, an integer, or an array of such values "
|
164
|
+
# :nocov:
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Outcome
|
3
|
+
class UnsuccessfulOutcomeError < StandardError
|
4
|
+
attr_accessor :errors
|
5
|
+
|
6
|
+
def initialize(errors)
|
7
|
+
self.errors = errors
|
8
|
+
|
9
|
+
message = errors.map(&:message).join(", ")
|
10
|
+
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def success(result)
|
17
|
+
new.tap do |outcome|
|
18
|
+
outcome.result = result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def errors(*errors)
|
23
|
+
errors = errors.flatten
|
24
|
+
|
25
|
+
if errors.empty?
|
26
|
+
# :nocov:
|
27
|
+
raise "No errors given"
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
|
31
|
+
new.tap do |outcome|
|
32
|
+
outcome.add_errors(errors)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def error(error)
|
37
|
+
errors(Util.array(error))
|
38
|
+
end
|
39
|
+
|
40
|
+
def raise!(errors)
|
41
|
+
self.errors(errors).raise! unless errors.empty?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :result
|
46
|
+
attr_reader :error_collection
|
47
|
+
|
48
|
+
def initialize(result: nil, errors: nil, error_collection: ErrorCollection.new)
|
49
|
+
@error_collection = error_collection
|
50
|
+
|
51
|
+
self.result = result
|
52
|
+
|
53
|
+
if errors
|
54
|
+
add_errors(errors)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
foobara_delegate :has_errors?,
|
59
|
+
:errors,
|
60
|
+
:each_error,
|
61
|
+
:has_error?,
|
62
|
+
:add_error,
|
63
|
+
:add_errors,
|
64
|
+
to: :error_collection
|
65
|
+
|
66
|
+
def success?
|
67
|
+
!has_errors?
|
68
|
+
end
|
69
|
+
|
70
|
+
def fatal?
|
71
|
+
errors.any?(&:fatal?)
|
72
|
+
end
|
73
|
+
|
74
|
+
def raise!
|
75
|
+
return if success?
|
76
|
+
|
77
|
+
if errors.size == 1
|
78
|
+
raise errors.first
|
79
|
+
else
|
80
|
+
raise UnsuccessfulOutcomeError, errors
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def result!
|
85
|
+
raise!
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
def errors_hash
|
90
|
+
error_collection.to_h
|
91
|
+
end
|
92
|
+
|
93
|
+
def errors_sentence
|
94
|
+
error_collection.to_sentence
|
95
|
+
end
|
96
|
+
|
97
|
+
def error_keys
|
98
|
+
error_collection.keys
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Foobara
|
2
|
+
class PossibleError
|
3
|
+
attr_accessor :key, :error_class, :data, :processor, :manually_added
|
4
|
+
|
5
|
+
# why can't we set path here?
|
6
|
+
def initialize(
|
7
|
+
error_class,
|
8
|
+
key: nil,
|
9
|
+
data: nil,
|
10
|
+
symbol: error_class.symbol,
|
11
|
+
category: error_class.category,
|
12
|
+
processor: nil
|
13
|
+
)
|
14
|
+
self.error_class = error_class
|
15
|
+
self.processor = processor
|
16
|
+
self.data = if data
|
17
|
+
data
|
18
|
+
elsif processor
|
19
|
+
{ processor.symbol => processor.declaration_data }
|
20
|
+
end
|
21
|
+
self.key = if key
|
22
|
+
if key.is_a?(ErrorKey)
|
23
|
+
key
|
24
|
+
else
|
25
|
+
ErrorKey.parse(key)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
ErrorKey.new(symbol:, category:)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def dup
|
33
|
+
PossibleError.new(
|
34
|
+
error_class,
|
35
|
+
key: key.dup,
|
36
|
+
data:
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def prepend_path!(...)
|
41
|
+
key.prepend_path!(...)
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepend_runtime_path!(...)
|
45
|
+
key.prepend_runtime_path!(...)
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: technically does not belong in this project but maybe it should
|
49
|
+
def foobara_manifest(to_include:)
|
50
|
+
to_include << error_class
|
51
|
+
|
52
|
+
if processor
|
53
|
+
processor_class = processor.class
|
54
|
+
to_include << processor_class
|
55
|
+
|
56
|
+
if processor.scoped_path_set?
|
57
|
+
# Unclear why nothing in the test suite passes through here.
|
58
|
+
# TODO: either test this or delete it.
|
59
|
+
# :nocov:
|
60
|
+
to_include << processor
|
61
|
+
processor_reference = processor.foobara_manifest_reference
|
62
|
+
# :nocov:
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
processor_manifest_data = data unless processor_reference
|
67
|
+
|
68
|
+
Util.remove_blank(
|
69
|
+
key.to_h.merge(
|
70
|
+
key: key.to_s,
|
71
|
+
error: error_class.foobara_manifest_reference,
|
72
|
+
processor: processor_reference,
|
73
|
+
processor_class: processor_class&.foobara_manifest_reference,
|
74
|
+
processor_manifest_data:,
|
75
|
+
manually_added:
|
76
|
+
)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Foobara.require_project_file("common", "error")
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
# NOTE: annoyingly this will clash with ::RuntimeError if not fully qualified when using
|
5
|
+
class RuntimeError < Error
|
6
|
+
abstract
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def category
|
10
|
+
:runtime
|
11
|
+
end
|
12
|
+
|
13
|
+
def fatal?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: why path instead of runtime path?
|
19
|
+
def initialize(message: nil, symbol: nil, context: nil, path: nil)
|
20
|
+
args = { message:, symbol:, context:, path: }.compact
|
21
|
+
super(**args.merge(category: self.class.category))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module Foobara::Concerns; end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Concern
|
3
|
+
# TODO: there seems to be a bug when extending classes. They do not get inheritance for free with
|
4
|
+
# this module as would be expected.
|
5
|
+
module IsConcern
|
6
|
+
def included(klass)
|
7
|
+
# If behavior is defined in Concern A and then included into Concern B, we need to make sure
|
8
|
+
# that when B is included it's also as if A were included.
|
9
|
+
# ClassMethods on A should exist on any object's class that included B.
|
10
|
+
# Any code-snippets to be ran when A is included should also be ran if B is included.
|
11
|
+
if Concern.foobara_concern?(klass)
|
12
|
+
if const_defined?(:ClassMethods, false)
|
13
|
+
Concern.foobara_class_methods_module_for(klass).include(const_get(:ClassMethods, false))
|
14
|
+
end
|
15
|
+
else
|
16
|
+
if const_defined?(:ClassMethods, false)
|
17
|
+
klass.extend(const_get(:ClassMethods, false))
|
18
|
+
end
|
19
|
+
|
20
|
+
ancestors.select { |mod| Concern.foobara_concern?(mod) }.reverse.each do |concern|
|
21
|
+
concern.instance_variable_get("@inherited_overridable_class_attr_accessors")&.each do |name|
|
22
|
+
var_name = "@#{name}"
|
23
|
+
klass.instance_variable_set(var_name, klass.instance_variable_get(var_name))
|
24
|
+
end
|
25
|
+
|
26
|
+
if concern.has_foobara_on_include_block?
|
27
|
+
klass.class_eval(&concern.foobara_on_include_block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_foobara_on_include_block?
|
36
|
+
!!@foobara_on_include
|
37
|
+
end
|
38
|
+
|
39
|
+
def foobara_on_include_block
|
40
|
+
@foobara_on_include
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_include(&block)
|
44
|
+
@foobara_on_include = block
|
45
|
+
end
|
46
|
+
|
47
|
+
def inherited_overridable_class_attr_accessor(*names)
|
48
|
+
@inherited_overridable_class_attr_accessors ||= []
|
49
|
+
@inherited_overridable_class_attr_accessors += names
|
50
|
+
|
51
|
+
Concern.foobara_class_methods_module_for(self).module_eval do
|
52
|
+
names.each do |name|
|
53
|
+
var_name = "@#{name}"
|
54
|
+
|
55
|
+
define_method name do
|
56
|
+
if instance_variable_defined?(var_name)
|
57
|
+
instance_variable_get(var_name)
|
58
|
+
else
|
59
|
+
superclass.send(name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_writer name
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def included(concern)
|
71
|
+
concern.extend(IsConcern)
|
72
|
+
end
|
73
|
+
|
74
|
+
def foobara_concern?(mod)
|
75
|
+
mod.singleton_class < IsConcern
|
76
|
+
end
|
77
|
+
|
78
|
+
def foobara_class_methods_module_for(klass)
|
79
|
+
unless klass.name
|
80
|
+
# :nocov:
|
81
|
+
raise "This does not work with anonymous classes"
|
82
|
+
# :nocov:
|
83
|
+
end
|
84
|
+
|
85
|
+
if klass.const_defined?(:ClassMethods, false)
|
86
|
+
klass.const_get(:ClassMethods, false)
|
87
|
+
else
|
88
|
+
Util.make_module "#{klass.name}::ClassMethods"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module Foobara::Delegate; end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Module
|
2
|
+
def foobara_delegate(*method_names, to:, allow_nil: false)
|
3
|
+
method_names.each do |method_name|
|
4
|
+
define_method method_name do |*args, **opts, &block|
|
5
|
+
target = to.is_a?(::Symbol) || to.is_a?(::String) ? send(to) : to
|
6
|
+
return nil if target.nil? && allow_nil
|
7
|
+
|
8
|
+
target.send(method_name, *args, **opts, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Domain
|
3
|
+
class << self
|
4
|
+
def install!
|
5
|
+
if @installed
|
6
|
+
# :nocov:
|
7
|
+
raise "Already registered Domain"
|
8
|
+
# :nocov:
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: delete this?
|
12
|
+
@installed = true
|
13
|
+
|
14
|
+
Namespace.global.foobara_add_category(:organization) { is_a?(Module) && foobara_organization? }
|
15
|
+
Namespace.global.foobara_add_category(:domain) { is_a?(Module) && foobara_domain? }
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_all
|
19
|
+
if Foobara::DomainMapper.instance_variable_defined?(:@foobara_domain_mappers_to_process)
|
20
|
+
Foobara::DomainMapper.remove_instance_variable(:@foobara_domain_mappers_to_process)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Domain
|
3
|
+
class DomainAlreadyExistsError < StandardError; end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def to_domain(object)
|
7
|
+
case object
|
8
|
+
when nil
|
9
|
+
global
|
10
|
+
when ::String, ::Symbol
|
11
|
+
domain = Namespace.global.foobara_lookup_domain(object)
|
12
|
+
|
13
|
+
unless domain
|
14
|
+
# :nocov:
|
15
|
+
raise NoSuchDomain, "Couldn't determine domain for #{object}"
|
16
|
+
# :nocov:
|
17
|
+
end
|
18
|
+
|
19
|
+
domain
|
20
|
+
when Foobara::Scoped
|
21
|
+
if object.is_a?(Module) && object.foobara_domain?
|
22
|
+
object
|
23
|
+
else
|
24
|
+
parent = object.scoped_namespace
|
25
|
+
|
26
|
+
if parent
|
27
|
+
to_domain(parent)
|
28
|
+
else
|
29
|
+
GlobalDomain
|
30
|
+
end
|
31
|
+
end
|
32
|
+
else
|
33
|
+
# :nocov:
|
34
|
+
raise NoSuchDomain, "Couldn't determine domain for #{object}"
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create(full_domain_name)
|
40
|
+
if Domain.to_domain(full_domain_name)
|
41
|
+
raise DomainAlreadyExistsError, "Domain #{full_domain_name} already exists"
|
42
|
+
end
|
43
|
+
rescue Domain::NoSuchDomain
|
44
|
+
begin
|
45
|
+
Util.make_module(full_domain_name) { foobara_domain! }
|
46
|
+
rescue Util::ParentModuleDoesNotExistError => e
|
47
|
+
# TODO: this doesn't feel like the right logic... how do we know this isn't a prefix instead of an
|
48
|
+
# organization?
|
49
|
+
Util.make_module(e.parent_name) { foobara_organization! }
|
50
|
+
Util.make_module(full_domain_name) { foobara_domain! }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def foobara_type_from_declaration(scoped, type_declaration)
|
55
|
+
domain = to_domain(scoped)
|
56
|
+
|
57
|
+
domain.foobara_type_from_declaration(type_declaration)
|
58
|
+
end
|
59
|
+
|
60
|
+
def current
|
61
|
+
to_domain(Namespace.current)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|