Class: Foobara::BuiltinTypes::AssociativeArray::SupportedProcessors::KeyTypeDeclaration

Inherits:
TypeDeclarations::ElementProcessor show all
Defined in:
foobara-0.0.110/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods inherited from Value::Processor

#always_applicable?, #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

#key_typeObject



6
7
8
# File 'foobara-0.0.110/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb', line 6

def key_type
  @key_type ||= type_for_declaration(key_type_declaration)
end

#possible_errorsObject



33
34
35
36
37
38
39
# File 'foobara-0.0.110/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb', line 33

def possible_errors
  super + key_type.possible_errors.map do |possible_error|
            possible_error = possible_error.dup
            possible_error.prepend_path!(:"#", :key)
            possible_error
          end
end

#process_value(attributes_hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'foobara-0.0.110/projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb', line 10

def process_value(attributes_hash)
  errors = []

  attributes_hash = attributes_hash.to_a.map.with_index do |(key, value), index|
    key_outcome = key_type.process_value(key)

    if key_outcome.success?
      key = key_outcome.result
    else
      key_outcome.each_error do |error|
        # Can' prepend path since we dont know if key is a symbolizable type...
        error.prepend_path!(index, :key)

        errors << error
      end
    end

    [key, value]
  end.to_h

  Outcome.new(result: attributes_hash, errors:)
end