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,257 @@
|
|
1
|
+
module Foobara
|
2
|
+
class CommandRegistry
|
3
|
+
include TruncatedInspect
|
4
|
+
|
5
|
+
foobara_instances_are_namespaces!
|
6
|
+
|
7
|
+
attr_accessor :authenticator, :default_allowed_rule
|
8
|
+
|
9
|
+
def initialize(authenticator: nil)
|
10
|
+
self.scoped_path = []
|
11
|
+
self.authenticator = authenticator
|
12
|
+
|
13
|
+
customized = %i[command domain organization]
|
14
|
+
|
15
|
+
Namespace.global.foobara_categories.keys.reverse.each do |symbol|
|
16
|
+
next if customized.include?(symbol)
|
17
|
+
|
18
|
+
proc = Namespace.global.foobara_categories[symbol]
|
19
|
+
|
20
|
+
foobara_add_category(symbol, &proc)
|
21
|
+
end
|
22
|
+
|
23
|
+
foobara_add_category_for_instance_of(:command, ExposedCommand)
|
24
|
+
foobara_add_category_for_instance_of(:domain, ExposedDomain)
|
25
|
+
foobara_add_category_for_instance_of(:organization, ExposedOrganization)
|
26
|
+
end
|
27
|
+
|
28
|
+
def register(command_class, **)
|
29
|
+
create_exposed_command(command_class, **)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_exposed_command(command_class, **)
|
33
|
+
full_domain_name = command_class.domain.scoped_full_name
|
34
|
+
exposed_domain = foobara_lookup_domain(full_domain_name) || build_and_register_exposed_domain(full_domain_name)
|
35
|
+
|
36
|
+
exposed_command = create_exposed_command_without_domain(command_class, **)
|
37
|
+
|
38
|
+
exposed_domain.foobara_register(exposed_command)
|
39
|
+
|
40
|
+
exposed_command
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO: eliminate this method
|
44
|
+
def create_exposed_command_without_domain(command_class, **)
|
45
|
+
ExposedCommand.new(command_class, **apply_defaults(**))
|
46
|
+
end
|
47
|
+
|
48
|
+
def apply_defaults(
|
49
|
+
inputs_transformers: nil,
|
50
|
+
result_transformers: nil,
|
51
|
+
errors_transformers: nil,
|
52
|
+
pre_commit_transformers: nil,
|
53
|
+
serializers: nil,
|
54
|
+
allowed_rule: default_allowed_rule,
|
55
|
+
authenticator: self.authenticator,
|
56
|
+
**opts
|
57
|
+
)
|
58
|
+
opts.merge(
|
59
|
+
inputs_transformers: [*inputs_transformers, *default_inputs_transformers],
|
60
|
+
result_transformers: [*result_transformers, *default_result_transformers],
|
61
|
+
errors_transformers: [*errors_transformers, *default_errors_transformers],
|
62
|
+
pre_commit_transformers: [*pre_commit_transformers, *default_pre_commit_transformers],
|
63
|
+
serializers: [*serializers, *default_serializers],
|
64
|
+
allowed_rule: allowed_rule && to_allowed_rule(allowed_rule),
|
65
|
+
authenticator:
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_and_register_exposed_domain(domain_full_name)
|
70
|
+
# TODO: would be nice to not have to do this...
|
71
|
+
domain_module = if domain_full_name.to_s == ""
|
72
|
+
GlobalDomain
|
73
|
+
else
|
74
|
+
Namespace.global.foobara_lookup_domain!(domain_full_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
full_organization_name = domain_module.foobara_full_organization_name
|
78
|
+
exposed_organization = foobara_lookup_organization(full_organization_name) ||
|
79
|
+
build_and_register_exposed_organization(full_organization_name)
|
80
|
+
|
81
|
+
exposed_domain = ExposedDomain.new(domain_module)
|
82
|
+
|
83
|
+
exposed_organization.foobara_register(exposed_domain)
|
84
|
+
exposed_domain.foobara_parent_namespace = exposed_organization
|
85
|
+
|
86
|
+
exposed_domain
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_and_register_exposed_organization(full_organization_name)
|
90
|
+
org = if full_organization_name.to_s == ""
|
91
|
+
GlobalOrganization
|
92
|
+
else
|
93
|
+
Namespace.global.foobara_lookup_organization!(full_organization_name)
|
94
|
+
end
|
95
|
+
|
96
|
+
exposed_organization = ExposedOrganization.new(org)
|
97
|
+
foobara_register(exposed_organization)
|
98
|
+
exposed_organization.foobara_parent_namespace = self
|
99
|
+
|
100
|
+
exposed_organization
|
101
|
+
end
|
102
|
+
|
103
|
+
def exposed_global_domain
|
104
|
+
exposed_global_organization.foobara_lookup_domain("") ||
|
105
|
+
build_and_register_exposed_domain("")
|
106
|
+
end
|
107
|
+
|
108
|
+
def exposed_global_organization
|
109
|
+
foobara_lookup_organization("") ||
|
110
|
+
build_and_register_exposed_organization("")
|
111
|
+
end
|
112
|
+
|
113
|
+
def [](name)
|
114
|
+
if name.is_a?(Class)
|
115
|
+
name.full_command_name
|
116
|
+
end
|
117
|
+
|
118
|
+
foobara_lookup(name)
|
119
|
+
end
|
120
|
+
|
121
|
+
def allowed_rule_registry
|
122
|
+
@allowed_rule_registry ||= {}
|
123
|
+
end
|
124
|
+
|
125
|
+
def allowed_rule(ruleish)
|
126
|
+
allowed_rule = to_allowed_rule(ruleish)
|
127
|
+
|
128
|
+
unless allowed_rule.symbol
|
129
|
+
# :nocov:
|
130
|
+
raise "Cannot register a rule without a symbol"
|
131
|
+
# :nocov:
|
132
|
+
end
|
133
|
+
|
134
|
+
allowed_rule_registry[allowed_rule.symbol] = allowed_rule
|
135
|
+
end
|
136
|
+
|
137
|
+
def allowed_rules(hash)
|
138
|
+
hash.map do |symbol, ruleish|
|
139
|
+
allowed_rule = to_allowed_rule(ruleish)
|
140
|
+
allowed_rule.symbol = symbol
|
141
|
+
|
142
|
+
allowed_rule(allowed_rule)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def default_inputs_transformers
|
147
|
+
@default_inputs_transformers ||= []
|
148
|
+
end
|
149
|
+
|
150
|
+
def add_default_inputs_transformer(transformer)
|
151
|
+
default_inputs_transformers << transformer
|
152
|
+
end
|
153
|
+
|
154
|
+
def default_result_transformers
|
155
|
+
@default_result_transformers ||= []
|
156
|
+
end
|
157
|
+
|
158
|
+
def add_default_result_transformer(transformer)
|
159
|
+
default_result_transformers << transformer
|
160
|
+
end
|
161
|
+
|
162
|
+
def default_errors_transformers
|
163
|
+
@default_errors_transformers ||= []
|
164
|
+
end
|
165
|
+
|
166
|
+
def add_default_errors_transformer(transformer)
|
167
|
+
default_errors_transformers << transformer
|
168
|
+
end
|
169
|
+
|
170
|
+
def default_pre_commit_transformers
|
171
|
+
@default_pre_commit_transformers ||= []
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_default_pre_commit_transformer(transformer)
|
175
|
+
default_pre_commit_transformers << transformer
|
176
|
+
end
|
177
|
+
|
178
|
+
def default_serializers
|
179
|
+
@default_serializers ||= []
|
180
|
+
end
|
181
|
+
|
182
|
+
def add_default_serializer(serializer)
|
183
|
+
default_serializers << serializer
|
184
|
+
end
|
185
|
+
|
186
|
+
def to_allowed_rule(object)
|
187
|
+
case object
|
188
|
+
when AllowedRule, nil
|
189
|
+
object
|
190
|
+
when ::String
|
191
|
+
to_allowed_rule(object.to_sym)
|
192
|
+
when ::Symbol
|
193
|
+
allowed_rule = allowed_rule_registry[object]
|
194
|
+
|
195
|
+
unless allowed_rule
|
196
|
+
# :nocov:
|
197
|
+
raise "No allowed rule found for #{object}"
|
198
|
+
# :nocov:
|
199
|
+
end
|
200
|
+
|
201
|
+
allowed_rule
|
202
|
+
when ::Hash
|
203
|
+
rule_attributes = AllowedRule.allowed_rule_attributes_type.process_value!(object)
|
204
|
+
|
205
|
+
allowed_rule = to_allowed_rule(rule_attributes[:logic])
|
206
|
+
|
207
|
+
if rule_attributes.key?(:symbol)
|
208
|
+
allowed_rule.symbol = rule_attributes[:symbol]
|
209
|
+
end
|
210
|
+
|
211
|
+
if rule_attributes.key?(:explanation)
|
212
|
+
allowed_rule.explanation = rule_attributes[:explanation]
|
213
|
+
end
|
214
|
+
|
215
|
+
allowed_rule.explanation ||= allowed_rule.symbol
|
216
|
+
|
217
|
+
allowed_rule
|
218
|
+
when ::Array
|
219
|
+
rules = object.map { |ruleish| to_allowed_rule(ruleish) }
|
220
|
+
|
221
|
+
procs = rules.map(&:block)
|
222
|
+
|
223
|
+
block = proc do
|
224
|
+
procs.any?(&:call)
|
225
|
+
end
|
226
|
+
|
227
|
+
allowed_rule = AllowedRule.new(&block)
|
228
|
+
|
229
|
+
if rules.all?(&:explanation)
|
230
|
+
allowed_rule.explanation = Util.to_or_sentence(rules.map(&:explanation))
|
231
|
+
end
|
232
|
+
|
233
|
+
allowed_rule
|
234
|
+
else
|
235
|
+
if object.respond_to?(:call)
|
236
|
+
AllowedRule.new(&object)
|
237
|
+
else
|
238
|
+
# :nocov:
|
239
|
+
raise "Not sure how to convert #{object} into an AllowedRule object"
|
240
|
+
# :nocov:
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def transformed_command_from_name(name)
|
246
|
+
foobara_lookup_command(name, mode: Namespace::LookupMode::RELAXED)&.transformed_command_class
|
247
|
+
end
|
248
|
+
|
249
|
+
def all_transformed_command_classes
|
250
|
+
foobara_all_command.map(&:transformed_command_class)
|
251
|
+
end
|
252
|
+
|
253
|
+
def each_transformed_command_class(&)
|
254
|
+
foobara_all_command.map(&:transformed_command_class).each(&)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Commands
|
4
|
+
class Describe < Foobara::Command
|
5
|
+
inputs manifestable: :duck,
|
6
|
+
request: :duck
|
7
|
+
result :associative_array
|
8
|
+
|
9
|
+
def execute
|
10
|
+
build_manifest
|
11
|
+
stamp_request_metadata
|
12
|
+
|
13
|
+
manifest
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :manifest
|
17
|
+
|
18
|
+
def build_manifest
|
19
|
+
self.manifest = if manifestable.is_a?(CommandConnector)
|
20
|
+
manifestable.foobara_manifest
|
21
|
+
else
|
22
|
+
manifestable.foobara_manifest(to_include: Set.new)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def stamp_request_metadata
|
27
|
+
manifest[:metadata] = {
|
28
|
+
# TODO: why is this here instead of in Http ??
|
29
|
+
url: request.url,
|
30
|
+
when: Time.now
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Commands
|
4
|
+
class ListCommands < Command
|
5
|
+
inputs request: :duck, # TODO: have some way to specify by Ruby class...
|
6
|
+
verbose: :boolean
|
7
|
+
|
8
|
+
result [
|
9
|
+
[
|
10
|
+
:string,
|
11
|
+
{
|
12
|
+
type: :string,
|
13
|
+
allow_nil: true
|
14
|
+
}
|
15
|
+
]
|
16
|
+
]
|
17
|
+
|
18
|
+
def execute
|
19
|
+
build_list
|
20
|
+
build_result
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :list
|
24
|
+
|
25
|
+
def build_list
|
26
|
+
self.list = command_connector.command_registry.all_transformed_command_classes
|
27
|
+
end
|
28
|
+
|
29
|
+
def verbose?
|
30
|
+
verbose
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_result
|
34
|
+
if verbose?
|
35
|
+
list.map do |command_class|
|
36
|
+
[command_class.full_command_name, command_class.description]
|
37
|
+
end
|
38
|
+
else
|
39
|
+
list.map do |command_class|
|
40
|
+
[command_class.full_command_name, nil]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def command_connector
|
46
|
+
request.command_connector
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Commands
|
4
|
+
class Ping < Foobara::Command
|
5
|
+
result :datetime
|
6
|
+
|
7
|
+
def execute
|
8
|
+
set_pong
|
9
|
+
|
10
|
+
pong
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :pong
|
14
|
+
|
15
|
+
def set_pong
|
16
|
+
self.pong = Time.now
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Commands
|
4
|
+
# NOTE: this assumes that the following has been executed to generate the `git_commit_info.json` file:
|
5
|
+
#
|
6
|
+
# git show -s --format='{"commit": "%H", "author": "%an <%ae>", "date": "%ad", "message": "%s"}' \
|
7
|
+
# HEAD > $1/git_commit_info.json
|
8
|
+
class QueryGitCommitInfo < Foobara::Command
|
9
|
+
GIT_COMMIT_INFO_FILE = "git_commit_info.json".freeze
|
10
|
+
|
11
|
+
# TODO: creating these types of error classes should be much much easier!
|
12
|
+
class GitCommitInfoFileNotFoundError < Foobara::RuntimeError
|
13
|
+
class << self
|
14
|
+
def message
|
15
|
+
format = '{"commit": "%H", "author": "%an <%ae>", "date": "%ad", "message": "%s"}'
|
16
|
+
|
17
|
+
<<~HERE
|
18
|
+
Could not find file: #{GIT_COMMIT_INFO_FILE}.#{" "}
|
19
|
+
Are you sure you are executing the following in the right place in your infrastructure?
|
20
|
+
|
21
|
+
git show -s --format='#{format}' HEAD > git_commit_info.json
|
22
|
+
|
23
|
+
HERE
|
24
|
+
end
|
25
|
+
|
26
|
+
def context_type_declaration
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
30
|
+
def context
|
31
|
+
{}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
possible_error GitCommitInfoFileNotFoundError
|
37
|
+
|
38
|
+
result commit: :string,
|
39
|
+
author: :string,
|
40
|
+
date: :string,
|
41
|
+
message: :string
|
42
|
+
|
43
|
+
def execute
|
44
|
+
validate_git_commit_info_exists
|
45
|
+
load_git_commit_info
|
46
|
+
|
47
|
+
git_commit_info
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_accessor :commit,
|
51
|
+
:author,
|
52
|
+
:date,
|
53
|
+
:message
|
54
|
+
|
55
|
+
def validate_git_commit_info_exists
|
56
|
+
unless File.exist?(GIT_COMMIT_INFO_FILE)
|
57
|
+
add_runtime_error GitCommitInfoFileNotFoundError
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_git_commit_info
|
62
|
+
git_commit_info = JSON.parse(File.read(GIT_COMMIT_INFO_FILE))
|
63
|
+
|
64
|
+
self.commit = git_commit_info["commit"]
|
65
|
+
self.author = git_commit_info["author"]
|
66
|
+
self.date = git_commit_info["date"]
|
67
|
+
self.message = git_commit_info["message"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_commit_info
|
71
|
+
{
|
72
|
+
commit:,
|
73
|
+
author:,
|
74
|
+
date:,
|
75
|
+
message:
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
class Request
|
4
|
+
include TruncatedInspect
|
5
|
+
|
6
|
+
# TODO: this feels like a smell of some sort...
|
7
|
+
attr_accessor :command_class, :command, :error, :command_connector, :serializers
|
8
|
+
|
9
|
+
def full_command_name
|
10
|
+
# :nocov:
|
11
|
+
raise "subclass responsibility"
|
12
|
+
# :nocov:
|
13
|
+
end
|
14
|
+
|
15
|
+
def inputs
|
16
|
+
# :nocov:
|
17
|
+
raise "subclass responsibility"
|
18
|
+
# :nocov:
|
19
|
+
end
|
20
|
+
|
21
|
+
def serializer
|
22
|
+
return @serializer if defined?(@serializer)
|
23
|
+
|
24
|
+
if serializers.nil? || serializers.empty?
|
25
|
+
@serializer = nil
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
actual_serializers = objects_to_serializers(serializers)
|
30
|
+
|
31
|
+
@serializer = if actual_serializers.size == 1
|
32
|
+
actual_serializers.first
|
33
|
+
else
|
34
|
+
Value::Processor::Pipeline.new(processors: actual_serializers)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def response_body
|
39
|
+
@response_body ||= begin
|
40
|
+
# TODO: should we have separate ways to register success and failure serializers?
|
41
|
+
body = success? ? result : error_collection
|
42
|
+
|
43
|
+
if serializer
|
44
|
+
serializer.process_value!(body)
|
45
|
+
else
|
46
|
+
body
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def success?
|
52
|
+
outcome.success?
|
53
|
+
end
|
54
|
+
|
55
|
+
def outcome
|
56
|
+
command.outcome
|
57
|
+
end
|
58
|
+
|
59
|
+
def result
|
60
|
+
outcome.result
|
61
|
+
end
|
62
|
+
|
63
|
+
def error_collection
|
64
|
+
outcome.error_collection
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def objects_to_serializers(objects)
|
70
|
+
objects.map do |object|
|
71
|
+
case object
|
72
|
+
when Class
|
73
|
+
object.new(self)
|
74
|
+
when Value::Processor
|
75
|
+
object
|
76
|
+
when ::Symbol, ::String
|
77
|
+
klass = Serializer.serializer_from_symbol(object)
|
78
|
+
|
79
|
+
unless klass
|
80
|
+
# :nocov:
|
81
|
+
raise "Could not find serializer for #{object}"
|
82
|
+
# :nocov:
|
83
|
+
end
|
84
|
+
|
85
|
+
klass.new(self)
|
86
|
+
else
|
87
|
+
if object.respond_to?(:call)
|
88
|
+
Value::Transformer.create(transform: object)
|
89
|
+
else
|
90
|
+
# :nocov:
|
91
|
+
raise "Not sure how to convert #{object} into a serializer"
|
92
|
+
# :nocov:
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
class Response
|
4
|
+
attr_accessor :status,
|
5
|
+
:body,
|
6
|
+
:request
|
7
|
+
|
8
|
+
def initialize(status:, body:, request:)
|
9
|
+
self.status = status
|
10
|
+
self.body = body
|
11
|
+
self.request = request
|
12
|
+
end
|
13
|
+
|
14
|
+
foobara_delegate :command, :error, to: :request
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
class Serializer < Value::Transformer
|
4
|
+
class << self
|
5
|
+
def serializer_from_symbol(symbol)
|
6
|
+
Util.descendants(Serializer).find do |klass|
|
7
|
+
name = Util.non_full_name(klass)
|
8
|
+
name = name.gsub(/Serializer$/, "")
|
9
|
+
name = Util.underscore(name)
|
10
|
+
|
11
|
+
symbol.to_s == name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def request
|
17
|
+
declaration_data
|
18
|
+
end
|
19
|
+
|
20
|
+
def transform(object)
|
21
|
+
serialize(object)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Serializers
|
4
|
+
class AggregateSerializer < SuccessSerializer
|
5
|
+
def serialize(object)
|
6
|
+
case object
|
7
|
+
when Entity
|
8
|
+
# TODO: handle polymorphism? Would require iterating over the result type not the object!
|
9
|
+
# Is there maybe prior art for this in the associations stuff?
|
10
|
+
unless object.loaded?
|
11
|
+
# :nocov:
|
12
|
+
raise "#{object} is not loaded so cannot serialize it"
|
13
|
+
# :nocov:
|
14
|
+
end
|
15
|
+
|
16
|
+
transform(object.attributes)
|
17
|
+
when Model
|
18
|
+
transform(object.attributes)
|
19
|
+
when Array
|
20
|
+
object.map { |element| transform(element) }
|
21
|
+
when Hash
|
22
|
+
object.to_h do |key, value|
|
23
|
+
[transform(key), transform(value)]
|
24
|
+
end
|
25
|
+
else
|
26
|
+
object
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Serializers
|
4
|
+
class AtomicSerializer < SuccessSerializer
|
5
|
+
def serialize(object)
|
6
|
+
if object.is_a?(Model)
|
7
|
+
if object.is_a?(Entity) && !object.loaded?
|
8
|
+
# :nocov:
|
9
|
+
raise "#{object} is not loaded so cannot serialize it"
|
10
|
+
# :nocov:
|
11
|
+
end
|
12
|
+
|
13
|
+
object = object.attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
entities_to_primary_keys_serializer.serialize(object)
|
17
|
+
end
|
18
|
+
|
19
|
+
def entities_to_primary_keys_serializer
|
20
|
+
@entities_to_primary_keys_serializer ||= EntitiesToPrimaryKeysSerializer.new(declaration_data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "success_serializer"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module CommandConnectors
|
5
|
+
module Serializers
|
6
|
+
class EntitiesToPrimaryKeysSerializer < SuccessSerializer
|
7
|
+
def serialize(object)
|
8
|
+
case object
|
9
|
+
when Entity
|
10
|
+
# TODO: handle polymorphism? Would require iterating over the result type not the object!
|
11
|
+
# Is there maybe prior art for this in the associations stuff?
|
12
|
+
object.primary_key
|
13
|
+
when Model
|
14
|
+
object.attributes
|
15
|
+
when Array
|
16
|
+
object.map { |element| serialize(element) }
|
17
|
+
when Hash
|
18
|
+
object.to_h do |key, value|
|
19
|
+
[serialize(key), serialize(value)]
|
20
|
+
end
|
21
|
+
else
|
22
|
+
object
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Foobara
|
2
|
+
require_project_file("command_connectors", "serializer")
|
3
|
+
|
4
|
+
module CommandConnectors
|
5
|
+
module Serializers
|
6
|
+
class ErrorsSerializer < Serializer
|
7
|
+
# TODO: always_applicable? instead?
|
8
|
+
def always_applicable?
|
9
|
+
!request.outcome.success?
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize(errors)
|
13
|
+
errors.map(&:to_h)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|