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,98 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module CommandConnectors
|
5
|
+
class Http < CommandConnector
|
6
|
+
class Request < CommandConnectors::Request
|
7
|
+
attr_accessor :path,
|
8
|
+
:method,
|
9
|
+
:headers,
|
10
|
+
:query_string,
|
11
|
+
:body,
|
12
|
+
:scheme,
|
13
|
+
:host,
|
14
|
+
:port,
|
15
|
+
:cookies,
|
16
|
+
:remote_ip,
|
17
|
+
:response_headers
|
18
|
+
|
19
|
+
def initialize(
|
20
|
+
path:,
|
21
|
+
method: nil,
|
22
|
+
headers: {},
|
23
|
+
query_string: "",
|
24
|
+
body: "",
|
25
|
+
scheme: nil,
|
26
|
+
host: nil,
|
27
|
+
port: nil,
|
28
|
+
cookies: nil,
|
29
|
+
remote_ip: nil
|
30
|
+
)
|
31
|
+
self.path = path
|
32
|
+
self.method = method
|
33
|
+
self.headers = headers
|
34
|
+
self.query_string = query_string
|
35
|
+
self.body = body
|
36
|
+
self.scheme = scheme
|
37
|
+
self.host = host
|
38
|
+
self.port = port
|
39
|
+
self.cookies = cookies
|
40
|
+
self.remote_ip = remote_ip
|
41
|
+
|
42
|
+
super()
|
43
|
+
end
|
44
|
+
|
45
|
+
def url
|
46
|
+
URI::Generic.build(
|
47
|
+
scheme:,
|
48
|
+
host:,
|
49
|
+
port:,
|
50
|
+
path:,
|
51
|
+
query: query_string.nil? || query_string.empty? ? nil : query_string
|
52
|
+
).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def inputs
|
56
|
+
@inputs ||= parsed_body.merge(parsed_query_string)
|
57
|
+
end
|
58
|
+
|
59
|
+
def full_command_name
|
60
|
+
unless defined?(@full_command_name)
|
61
|
+
set_action_and_command_name
|
62
|
+
end
|
63
|
+
|
64
|
+
@full_command_name
|
65
|
+
end
|
66
|
+
|
67
|
+
def parsed_body
|
68
|
+
body.empty? ? {} : JSON.parse(body)
|
69
|
+
end
|
70
|
+
|
71
|
+
def parsed_query_string
|
72
|
+
if query_string.nil? || query_string.empty?
|
73
|
+
{}
|
74
|
+
else
|
75
|
+
# TODO: override this in rack connector to use better rack utils
|
76
|
+
CGI.parse(query_string).transform_values!(&:first)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def action
|
81
|
+
unless defined?(@action)
|
82
|
+
set_action_and_command_name
|
83
|
+
end
|
84
|
+
|
85
|
+
@action
|
86
|
+
end
|
87
|
+
|
88
|
+
def argument
|
89
|
+
path.split("/")[2]
|
90
|
+
end
|
91
|
+
|
92
|
+
def set_action_and_command_name
|
93
|
+
@action, @full_command_name = path[1..].split("/")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
class Http < CommandConnector
|
4
|
+
class Response < CommandConnectors::Response
|
5
|
+
attr_accessor :headers
|
6
|
+
|
7
|
+
def initialize(headers:, **opts)
|
8
|
+
self.headers = headers
|
9
|
+
super(**opts)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
class Http < CommandConnector
|
4
|
+
include TruncatedInspect
|
5
|
+
|
6
|
+
def request_to_command(context)
|
7
|
+
if context.method == "OPTIONS"
|
8
|
+
# TODO: this feels a bit hacky and like overkill...
|
9
|
+
return Foobara::CommandConnectors::Http::Commands::GetOptions.new
|
10
|
+
end
|
11
|
+
|
12
|
+
command = super
|
13
|
+
|
14
|
+
if context.action == "help"
|
15
|
+
# Let's unwrap the transformed command to avoid serialization
|
16
|
+
# TODO: maybe instead register Help without serializers?
|
17
|
+
command = command.command
|
18
|
+
end
|
19
|
+
|
20
|
+
command
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: eliminate passing the command here...
|
24
|
+
def request_to_response(request)
|
25
|
+
command = request.command
|
26
|
+
outcome = command.outcome
|
27
|
+
|
28
|
+
# TODO: feels awkward to call this here... Maybe use result/errors transformers instead??
|
29
|
+
# Or call the serializer here??
|
30
|
+
body = command.respond_to?(:serialize_result) ? command.serialize_result : outcome.result
|
31
|
+
|
32
|
+
status = if outcome.success?
|
33
|
+
200
|
34
|
+
else
|
35
|
+
errors = outcome.errors
|
36
|
+
|
37
|
+
if errors.size == 1
|
38
|
+
error = errors.first
|
39
|
+
|
40
|
+
case error
|
41
|
+
when CommandConnector::UnknownError
|
42
|
+
500
|
43
|
+
when CommandConnector::NotFoundError, Foobara::Entity::NotFoundError
|
44
|
+
# TODO: we should not be coupled to Entities here...
|
45
|
+
body ||= "Not found"
|
46
|
+
404
|
47
|
+
when CommandConnector::UnauthenticatedError
|
48
|
+
401
|
49
|
+
when CommandConnector::NotAllowedError
|
50
|
+
403
|
51
|
+
end
|
52
|
+
end || 422
|
53
|
+
end
|
54
|
+
|
55
|
+
headers = headers_for(request)
|
56
|
+
|
57
|
+
Response.new(status:, headers:, body:, request:)
|
58
|
+
end
|
59
|
+
|
60
|
+
def headers_for(request)
|
61
|
+
response_headers = request.response_headers
|
62
|
+
|
63
|
+
if response_headers
|
64
|
+
static_headers.merge(response_headers)
|
65
|
+
else
|
66
|
+
static_headers.dup
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def static_headers
|
73
|
+
@static_headers ||= ENV.each_with_object({}) do |(key, value), headers|
|
74
|
+
match = key.match(/\AFOOBARA_HTTP_RESPONSE_HEADER_(.*)\z/)
|
75
|
+
|
76
|
+
if match
|
77
|
+
header_name = match[1].downcase.tr("_", "-")
|
78
|
+
headers[header_name] = value
|
79
|
+
end
|
80
|
+
end.freeze
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Common
|
3
|
+
class << self
|
4
|
+
def install!
|
5
|
+
Namespace.global.foobara_add_category_for_subclass_of(:processor_class, Value::Processor)
|
6
|
+
Namespace.global.foobara_add_category_for_instance_of(:processor, Value::Processor)
|
7
|
+
Namespace.global.foobara_add_category_for_subclass_of(:error, Error)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
module Foobara
|
2
|
+
# TODO: figure out how to share code between here and ErrorKey
|
3
|
+
# TODO: use this to implement computed attributes
|
4
|
+
class DataPath
|
5
|
+
class BadPathError < StandardError; end
|
6
|
+
|
7
|
+
# TODO: use this wherever it makes sense
|
8
|
+
EMPTY_PATH = [].freeze
|
9
|
+
|
10
|
+
class TooManyValuesAtPathError < StandardError
|
11
|
+
attr_accessor :path, :values
|
12
|
+
|
13
|
+
def initialize(path, values)
|
14
|
+
self.path = path
|
15
|
+
self.values = values
|
16
|
+
|
17
|
+
super(message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def message
|
21
|
+
"Expected only one value to be at #{path} but there were #{values.size}: #{values}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def to_s_type(key)
|
27
|
+
unless key.is_a?(DataPath)
|
28
|
+
key = new(key)
|
29
|
+
end
|
30
|
+
|
31
|
+
key.to_s_type
|
32
|
+
end
|
33
|
+
|
34
|
+
def values_at(data_path, object)
|
35
|
+
unless data_path.is_a?(DataPath)
|
36
|
+
data_path = new(data_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
data_path.values_at(object)
|
40
|
+
end
|
41
|
+
|
42
|
+
def value_at(data_path, object)
|
43
|
+
unless data_path.is_a?(DataPath)
|
44
|
+
data_path = new(data_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
data_path.value_at(object)
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_value_at(object, value, data_path)
|
51
|
+
unless data_path.is_a?(DataPath)
|
52
|
+
data_path = new(data_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
data_path.set_value_at(object, value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def prepend_path(key, *)
|
59
|
+
if key.is_a?(DataPath)
|
60
|
+
key.prepend(*)
|
61
|
+
else
|
62
|
+
key = new(key)
|
63
|
+
key.prepend!(*).to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def append_path(key, *)
|
68
|
+
if key.is_a?(DataPath)
|
69
|
+
key.append(*)
|
70
|
+
else
|
71
|
+
key = new(key)
|
72
|
+
key.append!(*).to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse(key_string)
|
77
|
+
new(key_string)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
attr_reader :path
|
82
|
+
|
83
|
+
# TODO: accept error_class instead of symbol/category??
|
84
|
+
def initialize(path = [])
|
85
|
+
path = path.to_s if path.is_a?(::Symbol)
|
86
|
+
path = path.split(".") if path.is_a?(::String)
|
87
|
+
|
88
|
+
self.path = path
|
89
|
+
end
|
90
|
+
|
91
|
+
def path=(path)
|
92
|
+
@path = normalize_all(path)
|
93
|
+
end
|
94
|
+
|
95
|
+
def prepend!(*prepend_parts)
|
96
|
+
if prepend_parts.size == 1
|
97
|
+
arg = prepend_parts.first
|
98
|
+
|
99
|
+
if arg.is_a?(Array)
|
100
|
+
prepend_parts = arg
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
self.path = [*prepend_parts, *path]
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def prepend(*)
|
109
|
+
dup.tap do |key|
|
110
|
+
key.prepend!(*)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def append!(*append_parts)
|
115
|
+
if append_parts.size == 1
|
116
|
+
arg = append_parts.first
|
117
|
+
|
118
|
+
if arg.is_a?(Array)
|
119
|
+
append_parts = arg
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
self.path = [*path, *append_parts]
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def append(*)
|
128
|
+
dup.tap do |key|
|
129
|
+
key.append!(*)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
INDEX_VALUE = /\A\d+\z/
|
134
|
+
|
135
|
+
def to_type!
|
136
|
+
path.map! do |part|
|
137
|
+
part.is_a?(Integer) ? :"#" : part
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_type
|
142
|
+
dup.tap(&:to_type!)
|
143
|
+
end
|
144
|
+
|
145
|
+
def to_s
|
146
|
+
path.join(".")
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_sym(...)
|
150
|
+
to_s(...).to_sym
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_s_type
|
154
|
+
to_type.to_s
|
155
|
+
end
|
156
|
+
|
157
|
+
def values_at(object, parts = path)
|
158
|
+
_values_at([object], parts)
|
159
|
+
end
|
160
|
+
|
161
|
+
def value_at(object, parts = path)
|
162
|
+
values = values_at(object, parts)
|
163
|
+
|
164
|
+
if values.size > 1
|
165
|
+
raise TooManyValuesAtPathError.new(path, values)
|
166
|
+
end
|
167
|
+
|
168
|
+
values.first
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_value_at(object, value, parts = path)
|
172
|
+
owner = value_at(object, parts[0..-2])
|
173
|
+
index = parts.last
|
174
|
+
|
175
|
+
if owner.is_a?(::Hash)
|
176
|
+
if owner.key?(index.to_s)
|
177
|
+
owner[index.to_s] = value
|
178
|
+
else
|
179
|
+
owner[index] = value
|
180
|
+
end
|
181
|
+
elsif owner.is_a?(::Array)
|
182
|
+
owner[index] = value
|
183
|
+
else
|
184
|
+
method = "#{index}="
|
185
|
+
if owner.respond_to?(method)
|
186
|
+
owner.send(method, value)
|
187
|
+
else
|
188
|
+
# :nocov:
|
189
|
+
raise BadPathError, "Bad path: #{parts}"
|
190
|
+
# :nocov:
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
value
|
195
|
+
end
|
196
|
+
|
197
|
+
# Helper method that determines if the path points to an array and none of the atoms along the way are also arrays.
|
198
|
+
# And that there's at least one atom (we are going to consider a collection to be "named" not an anonymous array.)
|
199
|
+
def simple_collection?
|
200
|
+
path.size > 1 && path.last == :"#" && path[0..-2].none? { |part| part == :"#" }
|
201
|
+
end
|
202
|
+
|
203
|
+
def ==(other)
|
204
|
+
self.class == other.class && path == other.path
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
|
209
|
+
def normalize_all(key_parts)
|
210
|
+
normalize(Util.array(key_parts))
|
211
|
+
end
|
212
|
+
|
213
|
+
def normalize(key_parts)
|
214
|
+
return nil if key_parts.nil?
|
215
|
+
|
216
|
+
case key_parts
|
217
|
+
when Array
|
218
|
+
key_parts.map do |key_part|
|
219
|
+
normalize(key_part)
|
220
|
+
end
|
221
|
+
when Symbol
|
222
|
+
normalize(key_parts.to_s)
|
223
|
+
when Integer
|
224
|
+
key_parts
|
225
|
+
when String
|
226
|
+
if key_parts.empty?
|
227
|
+
nil
|
228
|
+
elsif key_parts =~ INDEX_VALUE
|
229
|
+
key_parts.to_i
|
230
|
+
else
|
231
|
+
key_parts.to_sym
|
232
|
+
end
|
233
|
+
else
|
234
|
+
# :nocov:
|
235
|
+
raise ArgumentError,
|
236
|
+
"expected nil, a symbol, or a string, an integer, or an array of such values but was a #{key_parts.class}"
|
237
|
+
# :nocov:
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def _values_at(objects, parts = path)
|
242
|
+
return objects if parts.empty?
|
243
|
+
|
244
|
+
path_part, *parts = parts
|
245
|
+
|
246
|
+
objects = case path_part
|
247
|
+
when :"#"
|
248
|
+
objects.flatten.uniq
|
249
|
+
when Symbol
|
250
|
+
objects.map do |object|
|
251
|
+
if object.is_a?(::Hash)
|
252
|
+
if object.key?(path_part.to_s)
|
253
|
+
object[path_part.to_s]
|
254
|
+
else
|
255
|
+
object[path_part]
|
256
|
+
end
|
257
|
+
else
|
258
|
+
object.send(path_part)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
when Integer
|
262
|
+
objects.map { |value| value[path_part] }
|
263
|
+
else
|
264
|
+
# :nocov:
|
265
|
+
raise "Bad path part: #{path_part.inspect}"
|
266
|
+
# :nocov:
|
267
|
+
end.compact
|
268
|
+
|
269
|
+
_values_at(objects, parts)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Error < StandardError
|
3
|
+
foobara_autoregister_subclasses(default_namespace: Foobara::GlobalDomain)
|
4
|
+
|
5
|
+
include Manifestable
|
6
|
+
|
7
|
+
# TODO: rename :path to data_path
|
8
|
+
attr_accessor :error_key, :message, :context, :is_fatal
|
9
|
+
|
10
|
+
# Need to do this early so doing it here... not sure if this is OK as it couples namespaces and errors
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def abstract
|
14
|
+
@abstract = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def abstract?
|
18
|
+
@abstract
|
19
|
+
end
|
20
|
+
|
21
|
+
def symbol
|
22
|
+
Util.non_full_name_underscore(self).gsub(/_error$/, "").to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
# Is this actually used?
|
26
|
+
def path
|
27
|
+
ErrorKey::EMPTY_PATH
|
28
|
+
end
|
29
|
+
|
30
|
+
def runtime_path
|
31
|
+
ErrorKey::EMPTY_PATH
|
32
|
+
end
|
33
|
+
|
34
|
+
def category
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def message
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def context
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def fatal?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_h
|
51
|
+
{
|
52
|
+
category:,
|
53
|
+
symbol:,
|
54
|
+
# TODO: this is a bad dependency direction but maybe time to bite the bullet and finally merge these...
|
55
|
+
context_type_declaration: context_type&.declaration_data,
|
56
|
+
is_fatal: fatal?
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def foobara_manifest(to_include:)
|
61
|
+
types = types_depended_on.map do |t|
|
62
|
+
to_include << t
|
63
|
+
t.foobara_manifest_reference
|
64
|
+
end
|
65
|
+
|
66
|
+
base = nil
|
67
|
+
# don't bother including these core errors
|
68
|
+
unless superclass == Foobara::Error
|
69
|
+
base = superclass
|
70
|
+
to_include << base
|
71
|
+
end
|
72
|
+
|
73
|
+
manifest = super
|
74
|
+
|
75
|
+
unless types.empty?
|
76
|
+
manifest[:types_depended_on] = types.sort
|
77
|
+
end
|
78
|
+
|
79
|
+
h = manifest.merge(Util.remove_blank(to_h)).merge(
|
80
|
+
error_class: name
|
81
|
+
)
|
82
|
+
|
83
|
+
if base
|
84
|
+
h[:base_error] = base.foobara_manifest_reference
|
85
|
+
end
|
86
|
+
|
87
|
+
if abstract?
|
88
|
+
h[:abstract] = true
|
89
|
+
end
|
90
|
+
|
91
|
+
h
|
92
|
+
end
|
93
|
+
|
94
|
+
def subclass(
|
95
|
+
# TODO: technically context_type_declaration doesn't belong here. But maybe it should.
|
96
|
+
context_type_declaration:,
|
97
|
+
name: nil,
|
98
|
+
symbol: nil,
|
99
|
+
message: nil,
|
100
|
+
base_error: self,
|
101
|
+
category: base_error.category,
|
102
|
+
is_fatal: false,
|
103
|
+
abstract: false
|
104
|
+
)
|
105
|
+
name ||= "#{base_error.name}::#{Util.classify(symbol)}Error"
|
106
|
+
|
107
|
+
klass = Util.make_class_p(name, base_error) do
|
108
|
+
singleton_class.define_method :category do
|
109
|
+
category
|
110
|
+
end
|
111
|
+
|
112
|
+
if symbol
|
113
|
+
singleton_class.define_method :symbol do
|
114
|
+
symbol
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
singleton_class.define_method :fatal? do
|
119
|
+
is_fatal
|
120
|
+
end
|
121
|
+
|
122
|
+
singleton_class.define_method :context_type_declaration do
|
123
|
+
context_type_declaration
|
124
|
+
end
|
125
|
+
|
126
|
+
if message
|
127
|
+
singleton_class.define_method :message do
|
128
|
+
message
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
klass.abstract if abstract
|
134
|
+
|
135
|
+
klass
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
foobara_delegate :runtime_path,
|
140
|
+
:runtime_path=,
|
141
|
+
:category,
|
142
|
+
:category=,
|
143
|
+
:path,
|
144
|
+
:path=,
|
145
|
+
:symbol,
|
146
|
+
:symbol=,
|
147
|
+
to: :error_key
|
148
|
+
|
149
|
+
# TODO: seems like we should not allow the symbol to vary within instances of a class
|
150
|
+
# TODO: any items serializable in self.class.to_h should not be overrideable like this...
|
151
|
+
def initialize(
|
152
|
+
path: self.class.path,
|
153
|
+
runtime_path: self.class.runtime_path,
|
154
|
+
category: self.class.category,
|
155
|
+
message: self.class.message,
|
156
|
+
symbol: self.class.symbol,
|
157
|
+
context: self.class.context,
|
158
|
+
is_fatal: self.class.fatal?
|
159
|
+
)
|
160
|
+
self.error_key = ErrorKey.new
|
161
|
+
|
162
|
+
self.symbol = symbol
|
163
|
+
self.message = message
|
164
|
+
self.context = context
|
165
|
+
self.category = category
|
166
|
+
self.path = path
|
167
|
+
self.runtime_path = runtime_path
|
168
|
+
self.is_fatal = is_fatal
|
169
|
+
|
170
|
+
if !self.message.is_a?(String) || self.message.empty?
|
171
|
+
# :nocov:
|
172
|
+
raise "Bad error message, expected a string"
|
173
|
+
# :nocov:
|
174
|
+
end
|
175
|
+
|
176
|
+
super(message)
|
177
|
+
end
|
178
|
+
|
179
|
+
def fatal?
|
180
|
+
is_fatal
|
181
|
+
end
|
182
|
+
|
183
|
+
def key
|
184
|
+
error_key.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
def ==(other)
|
188
|
+
equal?(other) || eql?(other)
|
189
|
+
end
|
190
|
+
|
191
|
+
def eql?(other)
|
192
|
+
return false unless other.is_a?(Error)
|
193
|
+
|
194
|
+
symbol == other.symbol
|
195
|
+
end
|
196
|
+
|
197
|
+
def prepend_path!(...)
|
198
|
+
error_key.prepend_path!(...)
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
202
|
+
def to_h
|
203
|
+
{
|
204
|
+
key:,
|
205
|
+
path:,
|
206
|
+
runtime_path:,
|
207
|
+
category:,
|
208
|
+
symbol:,
|
209
|
+
message:,
|
210
|
+
context:,
|
211
|
+
is_fatal: fatal?
|
212
|
+
}
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|