Class: KathyLee::Definition::Binding

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.options = (KathyLee.attributes(attrib_name) || {}).merge(attributes)
  self.code_block = block
  self.has_ones = {}
  self.has_manys = {}
end

Instance Attribute Details

#code_blockObject

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_nameObject

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_manysObject

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_onesObject

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

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/kathy_lee/definition/binding.rb', line 5

def options
  @options
end

#parentObject

Returns the value of attribute parent.



10
11
12
# File 'lib/kathy_lee/definition/binding.rb', line 10

def parent
  @parent
end

#resultObject

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, options = {}, &block)
  options = {:size => 2}.merge(options)
  self.has_manys[factory.to_sym] = KathyLee::Definition::HasMany.new(factory.to_sym, {:options => options, :code_block => block, :klass => self.options.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, options = {}, &block)
  self.has_ones[factory.to_sym] = {:options => options, :code_block => block, 
                                   :klass => self.options.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