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

AttributesFactory.initialize()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 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