Class: KathyLee::Definition
- Inherits:
-
Object
- Object
- KathyLee::Definition
- Defined in:
- lib/kathy_lee/definition.rb
Overview
Houses the definition of a factory.
Examples:
KathyLee.define(:user) do
user = User.new()
... # do some more work
user
end
KathyLee.define(:user) do
has_one :blog # will call the :blog factory and assign it to the
# user object when it's returned from the block.
user = User.new()
... # do some more work
user
end
Defined Under Namespace
Classes: Binding, HasMany, HasOne, Relationship
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#code_block ⇒ Object
Returns the value of attribute code_block.
-
#factory_name ⇒ Object
Returns the value of attribute factory_name.
Instance Method Summary collapse
-
#build(attribs = {}) ⇒ Object
Execute the code block in it’s own building, with it’s own attributes and return the result.
-
#initialize(factory_name, attributes = {}, &block) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(factory_name, attributes = {}, &block) ⇒ Definition
Returns a new instance of Definition.
24 25 26 27 28 |
# File 'lib/kathy_lee/definition.rb', line 24 def initialize(factory_name, attributes = {}, &block) self.attributes = attributes self.factory_name = factory_name self.code_block = block end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
21 22 23 |
# File 'lib/kathy_lee/definition.rb', line 21 def attributes @attributes end |
#code_block ⇒ Object
Returns the value of attribute code_block.
22 23 24 |
# File 'lib/kathy_lee/definition.rb', line 22 def code_block @code_block end |
#factory_name ⇒ Object
Returns the value of attribute factory_name.
20 21 22 |
# File 'lib/kathy_lee/definition.rb', line 20 def factory_name @factory_name end |
Instance Method Details
#build(attribs = {}) ⇒ Object
Execute the code block in it’s own building, with it’s own attributes and return the result.
32 33 34 35 36 |
# File 'lib/kathy_lee/definition.rb', line 32 def build(attribs = {}) b = KathyLee::Definition::Binding.new(self.factory_name, self.attributes.merge(attribs), &self.code_block) b.process! return b.result end |