Sha256: 718aa14a6dec55ccba17364a05286d878adfaa98d7c1873afd77d2425aa20c61

Contents?: true

Size: 1.31 KB

Versions: 26

Compression:

Stored size: 1.31 KB

Contents

module Foobara
  module BuiltinTypes
    module AssociativeArray
      module SupportedProcessors
        class ValueTypeDeclaration < TypeDeclarations::ElementProcessor
          def value_type
            @value_type ||= type_for_declaration(value_type_declaration)
          end

          def process_value(attributes_hash)
            errors = []

            attributes_hash = attributes_hash.to_a.map.with_index do |(key, value), index|
              value_outcome = value_type.process_value(value)

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

                  errors << error
                end
              end

              [key, value]
            end.to_h

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

          def possible_errors
            super + value_type.possible_errors.map do |possible_error|
                      possible_error = possible_error.dup
                      possible_error.prepend_path!(:"#", :value)
                      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/value_type_declaration.rb
foobara-0.0.25 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.24 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.23 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.22 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.21 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.20 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.19 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.18 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.17 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.16 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.15 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.14 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.13 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.12 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.11 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.10 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.9 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.8 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb
foobara-0.0.7 projects/builtin_types/src/associative_array/supported_processors/value_type_declaration.rb