Class: Rubory::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/factories.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, context) ⇒ Factory

Returns a new instance of Factory.



86
87
88
89
90
91
# File 'lib/factories.rb', line 86

def initialize(name, context)
  @context = context
  @name = name
  @attributes = {}
  @counter = 0
end

Instance Method Details

#buildObject



95
96
97
# File 'lib/factories.rb', line 95

def build
  @context.create_instance class_name, Hash[ @attributes.to_a.collect{|attribute| [attribute[0], attribute[1].call(count)]} ]
end

#value_for(attribute, &block) ⇒ Object



92
93
94
# File 'lib/factories.rb', line 92

def value_for(attribute, &block)
  @attributes[attribute] = block;
end