| Total Complexity | 7 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | module Koine |
||
| 3 | class AttributesFactory |
||
| 4 | def initialize(options = {}) |
||
| 5 | @adapters = {} |
||
| 6 | @options = options |
||
| 7 | end |
||
| 8 | |||
| 9 | def create(target_object) |
||
| 10 | Attributes.new(target_object, adapters: @adapters, options: @options) |
||
| 11 | end |
||
| 12 | |||
| 13 | def add_attribute(name, adapter, &block) |
||
| 14 | adapter = coerce_adapter(adapter) |
||
| 15 | yield(adapter) if block |
||
| 16 | @adapters[name.to_sym] = adapter.freeze |
||
| 17 | end |
||
| 18 | |||
| 19 | def coerce_adapter(adapter) |
||
| 20 | return adapter unless adapter.instance_of?(::Symbol) |
||
| 21 | Object.const_get("Koine::Attributes::Adapter::#{adapter.to_s.capitalize}").new |
||
| 22 | end |
||
| 23 | |||
| 24 | def freeze |
||
| 25 | super |
||
| 26 | @adapters.freeze |
||
| 27 | @options.freeze |
||
| 28 | end |
||
| 29 | end |
||
| 30 | end |
||
| 32 |