Class: Koine::Attributes::AttributesFactory
- Inherits:
-
Object
- Object
- Koine::Attributes::AttributesFactory
- Defined in:
- lib/koine/attributes/attributes_factory.rb
Instance Method Summary collapse
- #add_attribute(name, adapter) {|adapter| ... } ⇒ Object
- #coerce_adapter(adapter) ⇒ Object
- #create(target_object) ⇒ Object
- #freeze ⇒ Object
-
#initialize(options = {}) ⇒ AttributesFactory
constructor
A new instance of AttributesFactory.
Constructor Details
#initialize(options = {}) ⇒ AttributesFactory
Returns a new instance of AttributesFactory.
4 5 6 7 |
# File 'lib/koine/attributes/attributes_factory.rb', line 4 def initialize( = {}) @adapters = {} @options = end |
Instance Method Details
#add_attribute(name, adapter) {|adapter| ... } ⇒ Object
13 14 15 16 17 |
# File 'lib/koine/attributes/attributes_factory.rb', line 13 def add_attribute(name, adapter, &block) adapter = coerce_adapter(adapter) yield(adapter) if block @adapters[name.to_sym] = adapter.freeze end |
#coerce_adapter(adapter) ⇒ Object
19 20 21 22 |
# File 'lib/koine/attributes/attributes_factory.rb', line 19 def coerce_adapter(adapter) return adapter unless adapter.instance_of?(::Symbol) Object.const_get("Koine::Attributes::Adapter::#{adapter.to_s.capitalize}").new end |
#create(target_object) ⇒ Object
9 10 11 |
# File 'lib/koine/attributes/attributes_factory.rb', line 9 def create(target_object) Attributes.new(target_object, adapters: @adapters, options: @options) end |
#freeze ⇒ Object
24 25 26 27 28 |
# File 'lib/koine/attributes/attributes_factory.rb', line 24 def freeze super @adapters.freeze @options.freeze end |