Class: KathyLee::Definition::Binding
- Inherits:
-
Object
- Object
- KathyLee::Definition::Binding
- Defined in:
- lib/kathy_lee/definition/binding.rb
Overview
Used to evaluate a KathyLee::Definition in it’s own ‘space’ (binding)
Instance Attribute Summary collapse
-
#code_block ⇒ Object
Returns the value of attribute code_block.
-
#factory_name ⇒ Object
Returns the value of attribute factory_name.
-
#has_manys ⇒ Object
Returns the value of attribute has_manys.
-
#has_ones ⇒ Object
Returns the value of attribute has_ones.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #has_many(factory, options = {}, &block) ⇒ Object
- #has_one(factory, options = {}, &block) ⇒ Object
-
#initialize(factory_name, attributes = {}, &block) ⇒ Binding
constructor
A new instance of Binding.
- #process! ⇒ Object
Constructor Details
#initialize(factory_name, attributes = {}, &block) ⇒ Binding
Returns a new instance of Binding.
12 13 14 15 16 17 18 19 |
# File 'lib/kathy_lee/definition/binding.rb', line 12 def initialize(factory_name, attributes = {}, &block) self.factory_name = factory_name attrib_name = attributes.delete(:attributes_for) || factory_name.to_sym self. = (KathyLee.attributes(attrib_name) || {}).merge(attributes) self.code_block = block self.has_ones = {} self.has_manys = {} end |
Instance Attribute Details
#code_block ⇒ Object
Returns the value of attribute code_block.
6 7 8 |
# File 'lib/kathy_lee/definition/binding.rb', line 6 def code_block @code_block end |
#factory_name ⇒ Object
Returns the value of attribute factory_name.
4 5 6 |
# File 'lib/kathy_lee/definition/binding.rb', line 4 def factory_name @factory_name end |
#has_manys ⇒ Object
Returns the value of attribute has_manys.
9 10 11 |
# File 'lib/kathy_lee/definition/binding.rb', line 9 def has_manys @has_manys end |
#has_ones ⇒ Object
Returns the value of attribute has_ones.
8 9 10 |
# File 'lib/kathy_lee/definition/binding.rb', line 8 def has_ones @has_ones end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/kathy_lee/definition/binding.rb', line 5 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/kathy_lee/definition/binding.rb', line 10 def parent @parent end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/kathy_lee/definition/binding.rb', line 7 def result @result end |
Instance Method Details
#has_many(factory, options = {}, &block) ⇒ Object
26 27 28 29 |
# File 'lib/kathy_lee/definition/binding.rb', line 26 def has_many(factory, = {}, &block) = {:size => 2}.merge() self.has_manys[factory.to_sym] = KathyLee::Definition::HasMany.new(factory.to_sym, {:options => , :code_block => block, :klass => self..delete(factory.to_sym)}) end |
#has_one(factory, options = {}, &block) ⇒ Object
21 22 23 24 |
# File 'lib/kathy_lee/definition/binding.rb', line 21 def has_one(factory, = {}, &block) self.has_ones[factory.to_sym] = {:options => , :code_block => block, :klass => self..delete(factory.to_sym)} end |
#process! ⇒ Object
31 32 33 34 35 |
# File 'lib/kathy_lee/definition/binding.rb', line 31 def process! self.result = instance_eval(&self.code_block) handle_has_ones handle_has_manys end |