Class: FactoryGirl::Definition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Definition

Returns a new instance of Definition.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



3
4
5
# File 'lib/factory_girl/definition.rb', line 3

def callbacks
  @callbacks
end

#declarationsObject (readonly)

Returns the value of attribute declarations.



3
4
5
# File 'lib/factory_girl/definition.rb', line 3

def declarations
  @declarations
end

#defined_traitsObject (readonly)

Returns the value of attribute defined_traits.



3
4
5
# File 'lib/factory_girl/definition.rb', line 3

def defined_traits
  @defined_traits
end

Instance Method Details

#add_callback(callback) ⇒ Object



36
37
38
# File 'lib/factory_girl/definition.rb', line 36

def add_callback(callback)
  @callbacks << callback
end

#attributesObject



15
16
17
# File 'lib/factory_girl/definition.rb', line 15

def attributes
  @attributes ||= declarations.attribute_list
end

#compileObject



19
20
21
# File 'lib/factory_girl/definition.rb', line 19

def compile
  attributes
end

#define_trait(trait) ⇒ Object



48
49
50
# File 'lib/factory_girl/definition.rb', line 48

def define_trait(trait)
  @defined_traits << trait
end

#inherit_traits(new_traits) ⇒ Object



32
33
34
# File 'lib/factory_girl/definition.rb', line 32

def inherit_traits(new_traits)
  @traits += new_traits
end

#overridableObject



23
24
25
26
# File 'lib/factory_girl/definition.rb', line 23

def overridable
  declarations.overridable
  self
end

#to_create(&block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/factory_girl/definition.rb', line 40

def to_create(&block)
  if block_given?
    @to_create = block
  else
    @to_create
  end
end

#traitsObject



28
29
30
# File 'lib/factory_girl/definition.rb', line 28

def traits
  @traits.reverse.map { |name| trait_by_name(name) }
end