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,320 @@
|
|
1
|
+
module Foobara
|
2
|
+
# TODO: either make this an abstract base class of ValueModel and Entity or rename it to ValueModel
|
3
|
+
# and have Entity inherit from it...
|
4
|
+
# TODO: also, why is this at the root level instead of in a project??
|
5
|
+
class Model
|
6
|
+
class NoSuchAttributeError < StandardError; end
|
7
|
+
class AttributeIsImmutableError < StandardError; end
|
8
|
+
|
9
|
+
include Concerns::Types
|
10
|
+
include Concerns::Reflection
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :is_abstract
|
14
|
+
|
15
|
+
def description(*args)
|
16
|
+
case args.size
|
17
|
+
when 0
|
18
|
+
@description
|
19
|
+
when 1
|
20
|
+
@description = args.first
|
21
|
+
else
|
22
|
+
# :nocov:
|
23
|
+
raise ArgumentError, "expected 0 or 1 argument, got #{args.size}"
|
24
|
+
# :nocov:
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def organization_name
|
29
|
+
domain.foobara_organization_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def domain_name
|
33
|
+
domain.foobara_domain_name
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO: would be nice to make this a universal concept via a concern
|
37
|
+
def abstract
|
38
|
+
@is_abstract = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def abstract?
|
42
|
+
@is_abstract
|
43
|
+
end
|
44
|
+
|
45
|
+
def closest_namespace_module
|
46
|
+
# TODO: Feels like we should use the autoset_namespace helpers here
|
47
|
+
mod = Util.module_for(self)
|
48
|
+
|
49
|
+
while mod
|
50
|
+
if mod.is_a?(Namespace::IsNamespace)
|
51
|
+
namespace = mod
|
52
|
+
break
|
53
|
+
end
|
54
|
+
|
55
|
+
mod = Util.module_for(mod)
|
56
|
+
end
|
57
|
+
|
58
|
+
if mod.nil? || mod == GlobalOrganization || mod == Foobara
|
59
|
+
GlobalDomain
|
60
|
+
else
|
61
|
+
namespace
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def domain
|
66
|
+
if model_type
|
67
|
+
model_type.foobara_domain
|
68
|
+
else
|
69
|
+
mod = Util.module_for(self)
|
70
|
+
|
71
|
+
while mod
|
72
|
+
if mod.foobara_domain?
|
73
|
+
namespace = mod
|
74
|
+
break
|
75
|
+
end
|
76
|
+
|
77
|
+
mod = Util.module_for(mod)
|
78
|
+
end
|
79
|
+
|
80
|
+
if namespace&.foobara_domain?
|
81
|
+
namespace
|
82
|
+
else
|
83
|
+
GlobalDomain
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def attribute_names
|
89
|
+
attributes_type.element_types.keys
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_attribute_name?(attribute_name)
|
93
|
+
attribute_names.include?(attribute_name.to_sym)
|
94
|
+
end
|
95
|
+
|
96
|
+
def validate_attribute_name!(attribute_name)
|
97
|
+
unless valid_attribute_name?(attribute_name)
|
98
|
+
raise NoSuchAttributeError, "No such attribute #{attribute_name} expected one of #{attribute_names}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def model_name
|
103
|
+
model_type&.scoped_name || Util.non_full_name(self)
|
104
|
+
rescue Foobara::Scoped::NoScopedPathSetError
|
105
|
+
# :nocov:
|
106
|
+
Util.non_full_name(self)
|
107
|
+
# :nocov:
|
108
|
+
end
|
109
|
+
|
110
|
+
def full_model_name
|
111
|
+
model_type&.scoped_full_name
|
112
|
+
end
|
113
|
+
|
114
|
+
def possible_errors(mutable: true)
|
115
|
+
if mutable == true
|
116
|
+
attributes_type.possible_errors
|
117
|
+
elsif mutable
|
118
|
+
element_types = attributes_type.element_types
|
119
|
+
|
120
|
+
p = []
|
121
|
+
|
122
|
+
Util.array(mutable).each do |attribute_name|
|
123
|
+
attribute_name = attribute_name.to_sym
|
124
|
+
|
125
|
+
# TODO: this doesn't feel quite right... we should be excluding errors so that we don't
|
126
|
+
# miss any that are on attributes_type unrelated to the elements.
|
127
|
+
element_types[attribute_name].possible_errors.each do |possible_error|
|
128
|
+
possible_error = possible_error.dup
|
129
|
+
possible_error.prepend_path!(attribute_name)
|
130
|
+
p << possible_error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
p
|
135
|
+
else
|
136
|
+
[]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def allowed_subclass_opts
|
141
|
+
%i[name model_module]
|
142
|
+
end
|
143
|
+
|
144
|
+
def subclass(**opts)
|
145
|
+
invalid_opts = opts.keys - allowed_subclass_opts
|
146
|
+
|
147
|
+
unless invalid_opts.empty?
|
148
|
+
# :nocov:
|
149
|
+
raise ArgumentError, "Invalid opts #{invalid_opts} expected only #{allowed_subclass_opts}"
|
150
|
+
# :nocov:
|
151
|
+
end
|
152
|
+
|
153
|
+
model_name = opts[:name]
|
154
|
+
|
155
|
+
if model_name.is_a?(::Symbol)
|
156
|
+
model_name = model_name.to_s
|
157
|
+
end
|
158
|
+
|
159
|
+
# TODO: How are we going to set the domain and organization?
|
160
|
+
model_class = Class.new(self) do
|
161
|
+
singleton_class.define_method :model_name do
|
162
|
+
model_name
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
if opts.key?(:model_module)
|
167
|
+
model_module = opts[:model_module]
|
168
|
+
|
169
|
+
if model_name.include?("::")
|
170
|
+
model_module_name = "#{model_module.name}::#{model_name.split("::")[..-2].join("::")}"
|
171
|
+
model_module = Util.make_module_p(model_module_name, tag: true)
|
172
|
+
end
|
173
|
+
|
174
|
+
const_name = model_name.split("::").last
|
175
|
+
|
176
|
+
model_module.const_set(const_name, model_class)
|
177
|
+
end
|
178
|
+
|
179
|
+
model_class
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
attr_accessor :mutable
|
184
|
+
|
185
|
+
def initialize(attributes = nil, options = {})
|
186
|
+
allowed_options = %i[validate mutable]
|
187
|
+
invalid_options = options.keys - allowed_options
|
188
|
+
|
189
|
+
unless invalid_options.empty?
|
190
|
+
# :nocov:
|
191
|
+
raise ArgumentError, "Invalid options #{invalid_options} expected only #{allowed_options}"
|
192
|
+
# :nocov:
|
193
|
+
end
|
194
|
+
|
195
|
+
validate = options[:validate]
|
196
|
+
|
197
|
+
if attributes.nil?
|
198
|
+
if validate
|
199
|
+
# :nocov:
|
200
|
+
raise ArgumentError, "Cannot use validate option without attributes"
|
201
|
+
# :nocov:
|
202
|
+
end
|
203
|
+
else
|
204
|
+
self.mutable = true
|
205
|
+
attributes.each_pair do |attribute_name, value|
|
206
|
+
write_attribute(attribute_name, value)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
mutable = options.key?(:mutable) ? options[:mutable] : true
|
211
|
+
|
212
|
+
self.mutable = if mutable.is_a?(::Array)
|
213
|
+
mutable.map(&:to_sym)
|
214
|
+
else
|
215
|
+
mutable
|
216
|
+
end
|
217
|
+
|
218
|
+
validate! if validate
|
219
|
+
end
|
220
|
+
|
221
|
+
foobara_delegate :model_name, :valid_attribute_name?, :validate_attribute_name!, to: :class
|
222
|
+
|
223
|
+
def attributes
|
224
|
+
@attributes ||= {}
|
225
|
+
end
|
226
|
+
|
227
|
+
def write_attribute(attribute_name, value)
|
228
|
+
attribute_name = attribute_name.to_sym
|
229
|
+
|
230
|
+
if mutable == true || mutable.include?(attribute_name)
|
231
|
+
outcome = cast_attribute(attribute_name, value)
|
232
|
+
attributes[attribute_name] = outcome.success? ? outcome.result : value
|
233
|
+
else
|
234
|
+
# :nocov:
|
235
|
+
raise AttributeIsImmutableError, "Cannot write attribute #{attribute_name} because it is not mutable"
|
236
|
+
# :nocov:
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def write_attribute!(attribute_name, value)
|
241
|
+
attribute_name = attribute_name.to_sym
|
242
|
+
attributes[attribute_name] = cast_attribute!(attribute_name, value)
|
243
|
+
end
|
244
|
+
|
245
|
+
def write_attributes(attributes)
|
246
|
+
attributes.each_pair do |attribute_name, value|
|
247
|
+
write_attribute(attribute_name, value)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def write_attributes!(attributes)
|
252
|
+
attributes.each_pair do |attribute_name, value|
|
253
|
+
write_attribute!(attribute_name, value)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def read_attribute(attribute_name)
|
258
|
+
attributes[attribute_name.to_sym]
|
259
|
+
end
|
260
|
+
|
261
|
+
def read_attribute!(attribute_name)
|
262
|
+
validate_attribute_name!(attribute_name)
|
263
|
+
read_attribute(attribute_name)
|
264
|
+
end
|
265
|
+
|
266
|
+
def cast_attribute(attribute_name, value)
|
267
|
+
attribute_type = attributes_type.element_types[attribute_name]
|
268
|
+
|
269
|
+
return Outcome.success(value) unless attribute_type
|
270
|
+
|
271
|
+
attribute_type.process_value(value).tap do |outcome|
|
272
|
+
unless outcome.success?
|
273
|
+
outcome.errors.each do |error|
|
274
|
+
error.prepend_path!(attribute_name)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def cast_attribute!(attribute_name, value)
|
281
|
+
validate_attribute_name!(attribute_name)
|
282
|
+
|
283
|
+
outcome = cast_attribute(attribute_name, value)
|
284
|
+
outcome.raise!
|
285
|
+
outcome.result
|
286
|
+
end
|
287
|
+
|
288
|
+
def valid?
|
289
|
+
attributes_type.process_value(attributes).success?
|
290
|
+
end
|
291
|
+
|
292
|
+
def validation_errors
|
293
|
+
attributes_type.process_value(attributes).errors
|
294
|
+
end
|
295
|
+
|
296
|
+
def validate!
|
297
|
+
attributes_type.process_value!(attributes)
|
298
|
+
end
|
299
|
+
|
300
|
+
def ==(other)
|
301
|
+
self.class == other.class && attributes == other.attributes
|
302
|
+
end
|
303
|
+
|
304
|
+
def eql?(other)
|
305
|
+
self == other
|
306
|
+
end
|
307
|
+
|
308
|
+
def hash
|
309
|
+
attributes.hash
|
310
|
+
end
|
311
|
+
|
312
|
+
def to_h
|
313
|
+
attributes
|
314
|
+
end
|
315
|
+
|
316
|
+
def to_json(*_args)
|
317
|
+
to_h.to_json
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Monorepo
|
3
|
+
# TODO: make this MonorepoProject and have a more generic Project so that other projects outside of the
|
4
|
+
# repo can have things like reset_all called on th.
|
5
|
+
class Project
|
6
|
+
attr_accessor :symbol
|
7
|
+
|
8
|
+
def initialize(symbol)
|
9
|
+
self.symbol = symbol
|
10
|
+
end
|
11
|
+
|
12
|
+
def project_path
|
13
|
+
"projects/#{symbol}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def require_path
|
17
|
+
"foobara/#{symbol}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def module_name
|
21
|
+
Util.classify(symbol)
|
22
|
+
end
|
23
|
+
|
24
|
+
def module
|
25
|
+
Foobara.const_get(module_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def load
|
29
|
+
require require_path
|
30
|
+
Util.require_directory("#{__dir__}/../../../../../#{project_path}/src")
|
31
|
+
end
|
32
|
+
|
33
|
+
def install!
|
34
|
+
if self.module.respond_to?(:install!)
|
35
|
+
self.module.install!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_all
|
40
|
+
if self.module.respond_to?(:reset_all)
|
41
|
+
self.module.reset_all
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def new_project_added(project)
|
46
|
+
if self.module.respond_to?(:new_project_added)
|
47
|
+
self.module.new_project_added(project)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "monorepo/project"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
class << self
|
5
|
+
def require_project_file(project, path)
|
6
|
+
require_relative("../../../#{project}/src/#{path}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset_alls
|
10
|
+
Monorepo.reset_alls
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO: We should rename this to Projects or something else because we need to manage this stuff for projects
|
15
|
+
# inside and outside of the monorepo.
|
16
|
+
module Monorepo
|
17
|
+
class << self
|
18
|
+
attr_accessor :is_installed
|
19
|
+
|
20
|
+
def all_projects
|
21
|
+
@all_projects ||= {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def projects(*symbols)
|
25
|
+
symbols.each do |symbol|
|
26
|
+
project(symbol)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def project(symbol)
|
31
|
+
if all_projects.key?(symbol)
|
32
|
+
# :nocov:
|
33
|
+
raise ArgumentError, "Project #{symbol} already loaded"
|
34
|
+
# :nocov:
|
35
|
+
end
|
36
|
+
|
37
|
+
project = Project.new(symbol)
|
38
|
+
project.load
|
39
|
+
|
40
|
+
all_projects[symbol] = project
|
41
|
+
|
42
|
+
if is_installed
|
43
|
+
project.install!
|
44
|
+
|
45
|
+
all_projects.each_pair do |key, existing_project|
|
46
|
+
next if key == symbol
|
47
|
+
|
48
|
+
existing_project.new_project_added(project)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def install!
|
54
|
+
self.is_installed = true
|
55
|
+
all_projects.each_value(&:install!)
|
56
|
+
end
|
57
|
+
|
58
|
+
def reset_alls
|
59
|
+
all_projects.each_value(&:reset_all)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Namespace
|
3
|
+
class AmbiguousRegistry < BaseRegistry
|
4
|
+
def registry
|
5
|
+
@registry ||= {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def register(scoped)
|
9
|
+
short_name = scoped.scoped_short_name
|
10
|
+
registry[short_name] ||= []
|
11
|
+
registry[short_name] |= [scoped]
|
12
|
+
end
|
13
|
+
|
14
|
+
def unregister(scoped)
|
15
|
+
short_name = scoped.scoped_short_name
|
16
|
+
entry = registry[short_name]
|
17
|
+
|
18
|
+
unless entry
|
19
|
+
# :nocov:
|
20
|
+
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
|
21
|
+
# :nocov:
|
22
|
+
end
|
23
|
+
|
24
|
+
registered = lookup([short_name])
|
25
|
+
|
26
|
+
unless registered
|
27
|
+
# :nocov:
|
28
|
+
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
|
29
|
+
# :nocov:
|
30
|
+
end
|
31
|
+
|
32
|
+
unless entry.delete(registered)
|
33
|
+
# :nocov:
|
34
|
+
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def lookup(path, filter = nil)
|
40
|
+
*prefix, short_name = path
|
41
|
+
matches = apply_filter(registry[short_name], filter)
|
42
|
+
|
43
|
+
if matches && !matches.empty?
|
44
|
+
_best_match(prefix, matches, path)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_scoped_without_filter(&)
|
49
|
+
registry.each_value do |scoped_objects|
|
50
|
+
scoped_objects.each(&)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def _best_match(prefix, matches, path)
|
57
|
+
candidates = nil
|
58
|
+
candidate_hits = -1
|
59
|
+
candidate_misses = 1
|
60
|
+
|
61
|
+
matches.each do |match|
|
62
|
+
hits, misses = _score(prefix, match)
|
63
|
+
|
64
|
+
if hits
|
65
|
+
if hits == candidate_hits
|
66
|
+
if misses == candidate_misses
|
67
|
+
candidates << match
|
68
|
+
elsif misses > candidate_misses
|
69
|
+
candidates = [match]
|
70
|
+
candidate_misses = misses
|
71
|
+
candidate_hits = hits
|
72
|
+
end
|
73
|
+
elsif hits > candidate_hits
|
74
|
+
candidates = [match]
|
75
|
+
candidate_misses = misses
|
76
|
+
candidate_hits = hits
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if candidates
|
82
|
+
if candidates.size > 1
|
83
|
+
raise AmbiguousLookupError,
|
84
|
+
"Ambiguous match for #{path.inspect}. Matches the following: #{candidates.inspect}"
|
85
|
+
end
|
86
|
+
|
87
|
+
candidates.first
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def _score(prefix, match)
|
92
|
+
prefix_path = Util.array(match.scoped_prefix)
|
93
|
+
matching_parts = prefix_path & prefix
|
94
|
+
|
95
|
+
if matching_parts == prefix
|
96
|
+
hits = matching_parts.size
|
97
|
+
misses = hits - prefix_path.size
|
98
|
+
|
99
|
+
[hits, misses]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Namespace
|
3
|
+
class AmbiguousLookupError < StandardError; end
|
4
|
+
|
5
|
+
class BaseRegistry
|
6
|
+
class WouldMakeRegistryAmbiguousError < StandardError; end
|
7
|
+
class NotRegisteredError < StandardError; end
|
8
|
+
|
9
|
+
def register(_scoped)
|
10
|
+
# :nocov:
|
11
|
+
raise "Subclass responsibility"
|
12
|
+
# :nocov:
|
13
|
+
end
|
14
|
+
|
15
|
+
def registered?(path)
|
16
|
+
!lookup(path).nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def unregister(_scoped)
|
20
|
+
# :nocov:
|
21
|
+
raise "Subclass responsibility"
|
22
|
+
# :nocov:
|
23
|
+
end
|
24
|
+
|
25
|
+
def lookup(_path, filter: nil)
|
26
|
+
# :nocov:
|
27
|
+
raise "Subclass responsibility"
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: should return an enumerator
|
32
|
+
def each_scoped(filter: nil, &block)
|
33
|
+
each_scoped_without_filter do |scoped|
|
34
|
+
scoped = apply_filter(scoped, filter) if filter
|
35
|
+
block.call(scoped) if scoped
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def all_scoped(filter: nil)
|
40
|
+
all = []
|
41
|
+
each_scoped(filter:) do |scoped|
|
42
|
+
all << scoped
|
43
|
+
end
|
44
|
+
all
|
45
|
+
end
|
46
|
+
|
47
|
+
def each_scoped_without_filter(&)
|
48
|
+
# :nocov:
|
49
|
+
raise "Subclass responsibility"
|
50
|
+
# :nocov:
|
51
|
+
end
|
52
|
+
|
53
|
+
def apply_filter(object, filter)
|
54
|
+
if filter
|
55
|
+
if object.is_a?(::Array)
|
56
|
+
object.select { |o| o.instance_eval(&filter) }
|
57
|
+
elsif object&.instance_eval(&filter)
|
58
|
+
object
|
59
|
+
end
|
60
|
+
else
|
61
|
+
object
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|