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

HashOf   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
dl 21
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce_not_nil() 11 11 1
A initialize() 5 5 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
        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