Sha256: 2ed0acc083f1ecdfb62e08a5d9d8e5b750518b2c37a8cc9d078f7dca0a42c5a5

Contents?: true

Size: 1.28 KB

Versions: 26

Compression:

Stored size: 1.28 KB

Contents

module Foobara
  module BuiltinTypes
    module AssociativeArray
      module SupportedProcessors
        class KeyTypeDeclaration < TypeDeclarations::ElementProcessor
          def key_type
            @key_type ||= type_for_declaration(key_type_declaration)
          end

          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

          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
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.25 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.24 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.23 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.22 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.21 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.20 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.19 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.18 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.17 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.16 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.15 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.14 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.13 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.12 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.11 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.10 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.9 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.8 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb
foobara-0.0.7 projects/builtin_types/src/associative_array/supported_processors/key_type_declaration.rb