Class: Foobara::BuiltinTypes::Attributes::SupportedProcessors::ElementTypeDeclarations
- Inherits:
-
TypeDeclarations::ElementProcessor
- Object
- Value::Processor
- Types::ElementProcessor
- TypeDeclarations::ElementProcessor
- Foobara::BuiltinTypes::Attributes::SupportedProcessors::ElementTypeDeclarations
- Defined in:
- foobara-0.0.110/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb
Defined Under Namespace
Classes: UnexpectedAttributesError
Instance Attribute Summary
Attributes inherited from Value::Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
Instance Method Summary collapse
- #allowed_attributes ⇒ Object
- #applicable?(value) ⇒ Boolean
- #possible_errors ⇒ Object
- #process_value(attributes_hash) ⇒ Object
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods inherited from Value::Processor
#always_applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, error_classes, #error_context, #error_message, #error_path, foobara_manifest, #foobara_manifest, #initialize, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #priority, #process_outcome, #process_outcome!, #process_value!, processor_name, requires_declaration_data?, requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol
Methods included from IsManifestable
#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches
Constructor Details
This class inherits a constructor from Foobara::Value::Processor
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor
Instance Method Details
#allowed_attributes ⇒ Object
25 26 27 |
# File 'foobara-0.0.110/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb', line 25 def allowed_attributes @allowed_attributes ||= declaration_data.keys end |
#applicable?(value) ⇒ Boolean
21 22 23 |
# File 'foobara-0.0.110/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb', line 21 def applicable?(value) value.is_a?(::Hash) end |
#possible_errors ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'foobara-0.0.110/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb', line 70 def possible_errors possibilities = [*super] element_type_declarations.each_pair do |attribute_name, attribute_declaration| attribute_type = type_for_declaration(attribute_declaration) attribute_type.possible_errors.each do |possible_error| possible_error = possible_error.dup possible_error.prepend_path!(attribute_name) possibilities << possible_error end end possibilities end |
#process_value(attributes_hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'foobara-0.0.110/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb', line 29 def process_value(attributes_hash) attributes_hash = Util.deep_dup(attributes_hash) unexpected_attributes = attributes_hash.keys - allowed_attributes unless unexpected_attributes.empty? return Outcome.error( build_error( attributes_hash, message: "Unexpected attributes #{ unexpected_attributes }. Expected only #{allowed_attributes}", context: { unexpected_attributes:, allowed_attributes: } ) ) end errors = [] attributes_hash.each_pair do |attribute_name, attribute_value| attribute_type_declaration = element_type_declarations[attribute_name] attribute_type = type_for_declaration(attribute_type_declaration) attribute_outcome = attribute_type.process_value(attribute_value) if attribute_outcome.success? attributes_hash[attribute_name] = attribute_outcome.result else attribute_outcome.each_error do |error| error.path = [attribute_name, *error.path] errors << error end end end Outcome.new(result: attributes_hash, errors:) end |