Class: FactoryGirl::Definition Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, base_traits = []) ⇒ Definition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Definition.



6
7
8
9
10
11
12
13
14
# File 'lib/factory_girl/definition.rb', line 6

def initialize(name = nil, base_traits = [])
  @declarations      = DeclarationList.new(name)
  @callbacks         = []
  @defined_traits    = []
  @to_create         = nil
  @base_traits       = base_traits
  @additional_traits = []
  @constructor       = nil
end

Instance Attribute Details

#callbacksObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def callbacks
  @callbacks
end

#constructorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def constructor
  @constructor
end

#declarationsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def declarations
  @declarations
end

#defined_traitsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def defined_traits
  @defined_traits
end

Instance Method Details

#add_callback(callback) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/factory_girl/definition.rb', line 45

def add_callback(callback)
  @callbacks << callback
end

#append_traits(new_traits) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
# File 'lib/factory_girl/definition.rb', line 41

def append_traits(new_traits)
  @additional_traits += new_traits
end

#attributesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def attributes
  @attributes ||= declarations.attribute_list
end

#compileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def compile
  attributes
end

#compiled_constructorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/factory_girl/definition.rb', line 53

def compiled_constructor
  definition_list.constructor
end

#compiled_to_createObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def compiled_to_create
  definition_list.to_create
end

#define_constructor(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
# File 'lib/factory_girl/definition.rb', line 73

def define_constructor(&block)
  @constructor = block
end

#define_trait(trait) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/factory_girl/definition.rb', line 69

def define_trait(trait)
  @defined_traits << trait
end

#definition_listObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def definition_list
  DefinitionList.new(
    base_traits.map(&:definition) + [self] + additional_traits.map(&:definition)
  )
end

#inherit_traits(new_traits) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def inherit_traits(new_traits)
  @base_traits += new_traits
end

#overridableObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def overridable
  declarations.overridable
  self
end

#skip_createObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/factory_girl/definition.rb', line 65

def skip_create
  @to_create = ->(instance) { }
end

#to_create(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
# File 'lib/factory_girl/definition.rb', line 57

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