Class: KathyLee::Definition::HasMany

Inherits:
Relationship show all
Defined in:
lib/kathy_lee/definition/has_many.rb

Instance Attribute Summary collapse

Attributes inherited from Relationship

#code_block, #factory, #klass, #options

Instance Method Summary collapse

Constructor Details

#initialize(factory, options = {}) ⇒ HasMany

Returns a new instance of HasMany.



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

def initialize(factory, options = {})
  super(factory, options)
  self.size = (self.options.delete(:size) || 2)
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



2
3
4
# File 'lib/kathy_lee/definition/has_many.rb', line 2

def size
  @size
end

Instance Method Details

#buildObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kathy_lee/definition/has_many.rb', line 9

def build
  results = []
  self.size.times do
    if self.klass
      results << self.klass
    else
      if self.code_block
        b = KathyLee::Definition::Binding.new(self.factory, self.options, self.code_block)
        b.process!
        results << b.result
      else
        results << KathyLee.build(self.factory, self.options)
      end
    end
  end
  [results].flatten
end