Sha256: a278a617a374c24eed3c74113d3376024c8f9540743ac788c961efb528d17c5a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Koine
  module Attributes
    module Adapter
      class HashOf < Base
        def initialize(key_adapter, value_adapter)
          @key_adapter = key_adapter || raise(ArgumentError, 'Invalid key adapter')
          @value_adapter = value_adapter || raise(ArgumentError, 'Invalid value adapter')
          with_default_value({})
        end

        def for_keys
          @key_adapter
        end

        def for_values
          @value_adapter
        end

        def with_attribute_name(name)
          @key_adapter.with_attribute_name(name)
          @value_adapter.with_attribute_name(name)
          super(name)
        end

        private

        def coerce_not_nil(hash)
          secure do
            {}.tap do |new_hash|
              hash.each do |key, value|
                key = @key_adapter.coerce(key)
                value = @value_adapter.coerce(value)
                new_hash[key] = value
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
koine-attributes-1.2.4 lib/koine/attributes/adapter/hash_of.rb