Completed
Push — master ( 681fa7...7087b8 )
by Marcelo
01:12
created

Base   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 26
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 3 1
A default_value() 0 5 1
A with_default_value() 0 5 2
A secure() 0 5 2
1
module Koine
2
  module Attributes
3
    module Adapter
4
      class Base
5
        def coerce(*_values)
6
          raise NotImplementedError
7
        end
8
9
        def default_value
10
          @default_value.respond_to?(:call) &&
11
            @default_value.call ||
12
            @default_value
13
        end
14
15
        def with_default_value(value = nil, &block)
16
          @default_value = value
17
          @default_value = block if block
18
          self
19
        end
20
21
        protected
22
23
        # duplicates if possible and freezes object
24
        def secure
25
          value = yield
26
          value = value.dup if value.respond_to?(:dup)
27
          value.freeze
28
        end
29
      end
30
    end
31
  end
32
end
33