Class: Manufactory::Adapter
Overview
Adapter.new(User, :admin, age: 24)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callables ⇒ Object
readonly
Returns the value of attribute callables.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #has_association?(object, attribute) ⇒ Boolean
-
#initialize(klass, name, callables) ⇒ Adapter
constructor
A new instance of Adapter.
- #run(attributes = Hash.new) ⇒ Object
Constructor Details
#initialize(klass, name, callables) ⇒ Adapter
40 41 42 43 44 |
# File 'lib/manufactory.rb', line 40 def initialize(klass, name, callables) @klass = klass @name = name @callables = callables end |
Instance Attribute Details
#callables ⇒ Object (readonly)
Returns the value of attribute callables.
39 40 41 |
# File 'lib/manufactory.rb', line 39 def callables @callables end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
39 40 41 |
# File 'lib/manufactory.rb', line 39 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
39 40 41 |
# File 'lib/manufactory.rb', line 39 def name @name end |
Instance Method Details
#has_association?(object, attribute) ⇒ Boolean
57 58 59 |
# File 'lib/manufactory.rb', line 57 def has_association?(object, attribute) false end |
#run(attributes = Hash.new) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/manufactory.rb', line 46 def run(attributes = Hash.new) blueprint = klass.blueprints[name.to_sym] raise "No blueprint #{name} for class #{klass}" if blueprint.nil? default_attributes = Hash.new object = klass.new(default_attributes) # will be discarded at the end self.callables.each do |callable| default_attributes.merge!(DSL.new(self, object, callable).run) end self.initialize_object(klass, default_attributes, attributes) end |