Sha256: 96f77eb3a208ac465439ad22b81ea5c9ef9cacf01b3db8fc72370d0c4bc33b44

Contents?: true

Size: 693 Bytes

Versions: 3

Compression:

Stored size: 693 Bytes

Contents

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 coerce(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

3 entries across 3 versions & 1 rubygems

Version Path
koine-attributes-0.2.3 lib/koine/attributes/adapter/hash_of.rb
koine-attributes-0.2.2 lib/koine/attributes/adapter/hash_of.rb
koine-attributes-0.2.1 lib/koine/attributes/adapter/hash_of.rb