Completed
Push — master ( c24669...17b1aa )
by Marcelo
37s
created

HashOf.coerce()   A

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
1
module Koine
2
  module Attributes
3
    module Adapter
4 View Code Duplication
      class HashOf < Base
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5
        def initialize(key_adapter, value_adapter)
6
          @key_adapter = key_adapter || raise(ArgumentError, 'Invalid key adapter')
7
          @value_adapter = value_adapter || raise(ArgumentError, 'Invalid value adapter')
8
          with_default_value({})
9
        end
10
11
        private
12
13
        def coerce_not_nil(hash)
14
          secure do
15
            {}.tap do |new_hash|
16
              hash.each do |key, value|
17
                key = @key_adapter.coerce(key)
18
                value = @value_adapter.coerce(value)
19
                new_hash[key] = value
20
              end
21
            end
22
          end
23
        end
24
      end
25
    end
26
  end
27
end
28