Completed
Pull Request — master (#12)
by Marcelo
01:27
created

HashOf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 29
loc 29
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce_not_nil() 11 11 1
A initialize() 5 5 1
A for_values() 3 3 1
A for_keys() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
        def for_keys
12
          @key_adapter
13
        end
14
15
        def for_values
16
          @value_adapter
17
        end
18
19
        private
20
21
        def coerce_not_nil(hash)
22
          secure do
23
            {}.tap do |new_hash|
24
              hash.each do |key, value|
25
                key = @key_adapter.coerce(key)
26
                value = @value_adapter.coerce(value)
27
                new_hash[key] = value
28
              end
29
            end
30
          end
31
        end
32
      end
33
    end
34
  end
35
end
36