Class: KathyLee::Definition::HasMany
- Inherits:
-
Relationship
- Object
- Relationship
- KathyLee::Definition::HasMany
- Defined in:
- lib/kathy_lee/definition/has_many.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
Attributes inherited from Relationship
#code_block, #factory, #klass, #options
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(factory, options = {}) ⇒ HasMany
constructor
A new instance of HasMany.
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, = {}) super(factory, ) self.size = (self..delete(:size) || 2) end |
Instance Attribute Details
#size ⇒ Object
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
#build ⇒ Object
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., self.code_block) b.process! results << b.result else results << KathyLee.build(self.factory, self.) end end end [results].flatten end |