Class: Manufactory::DSL
Overview
DSL is used to execute the blueprint and construct an object. The blueprint is instance_eval’d against the Lathe.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#blueprint ⇒ Object
readonly
Returns the value of attribute blueprint.
-
#object {|@object| ... } ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #assigned_attributes ⇒ Object
-
#initialize(adapter, object, blueprint) ⇒ DSL
constructor
A new instance of DSL.
- #method_missing(symbol, *args, &block) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(adapter, object, blueprint) ⇒ DSL
Returns a new instance of DSL.
8 9 10 11 12 |
# File 'lib/manufactory/dsl.rb', line 8 def initialize(adapter, object, blueprint) @adapter = adapter @blueprint = blueprint @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/manufactory/dsl.rb', line 24 def method_missing(symbol, *args, &block) if attribute_assigned?(symbol) # If we've already assigned the attribute, return that. self.object.send(symbol) elsif @adapter.has_association?(self.object, symbol) && !nil_or_empty?(self.object.send(symbol)) # If the attribute is an association and is already assigned, return that. self.object.send(symbol) else # Otherwise generate a value and assign it. assigned_attributes[symbol] = generate_attribute_value(symbol, *args, &block) end end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/manufactory/dsl.rb', line 7 def adapter @adapter end |
#blueprint ⇒ Object (readonly)
Returns the value of attribute blueprint.
7 8 9 |
# File 'lib/manufactory/dsl.rb', line 7 def blueprint @blueprint end |
#object {|@object| ... } ⇒ Object (readonly)
Returns the value of attribute object.
7 8 9 |
# File 'lib/manufactory/dsl.rb', line 7 def object @object end |