| Total Complexity | 7 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | module Koine |
||
| 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 | |||
| 28 | def freeze |
||
| 29 | super |
||
| 30 | @attributes.freeze |
||
| 31 | @options.freeze |
||
| 32 | end |
||
| 33 | end |
||
| 34 | end |
||
| 36 |