class FactoryGirl::Definition
Attributes
callbacks[R]
declarations[R]
defined_traits[R]
Public Class Methods
new(name = nil)
click to toggle source
# File lib/factory_girl/definition.rb, line 5 def initialize(name = nil) @declarations = DeclarationList.new(name) @callbacks = [] @defined_traits = [] @to_create = lambda {|instance| instance.save! } @traits = [] end
Public Instance Methods
add_callback(callback)
click to toggle source
# File lib/factory_girl/definition.rb, line 36 def add_callback(callback) @callbacks << callback end
attributes()
click to toggle source
# File lib/factory_girl/definition.rb, line 15 def attributes @attributes ||= declarations.attribute_list end
compile()
click to toggle source
# File lib/factory_girl/definition.rb, line 19 def compile attributes end
define_trait(trait)
click to toggle source
# File lib/factory_girl/definition.rb, line 48 def define_trait(trait) @defined_traits << trait end
inherit_traits(new_traits)
click to toggle source
# File lib/factory_girl/definition.rb, line 32 def inherit_traits(new_traits) @traits += new_traits end
overridable()
click to toggle source
# File lib/factory_girl/definition.rb, line 23 def overridable declarations.overridable self end
to_create(&block)
click to toggle source
# File lib/factory_girl/definition.rb, line 40 def to_create(&block) if block_given? @to_create = block else @to_create end end
traits()
click to toggle source
# File lib/factory_girl/definition.rb, line 28 def traits @traits.reverse.map { |name| trait_by_name(name) } end
Private Instance Methods
trait_by_name(name)
click to toggle source
# File lib/factory_girl/definition.rb, line 54 def trait_by_name(name) trait_for(name) || FactoryGirl.trait_by_name(name) end
trait_for(name)
click to toggle source
# File lib/factory_girl/definition.rb, line 58 def trait_for(name) defined_traits.detect {|trait| trait.name == name } end