Completed
Pull Request — master (#5)
by Marcelo
31s
created

AttributesFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 4 1
A coerce_adapter() 0 4 2
A add_attribute() 0 5 2
A create() 0 7 1
1
module Koine
2
  module Attributes
3
    class AttributesFactory
4
      def initialize(options = {})
5
        @attributes = {}
6
        @options = options
7
      end
8
9
      def create(target_object)
10
        Attributes.new(
11
          target_object,
12
          attributes: @attributes,
13
          options: @options
14
        )
15
      end
16
17
      def add_attribute(name, adapter, &block)
18
        adapter = coerce_adapter(adapter)
19
        block.call(adapter) if block
20
        @attributes[name.to_sym] = adapter
21
      end
22
23
      def coerce_adapter(adapter)
24
        return adapter unless adapter.instance_of?(::Symbol)
25
        Object.const_get("Koine::Attributes::Adapter::#{adapter.to_s.capitalize}").new
26
      end
27
    end
28
  end
29
end
30