Class: FactoryGirl::Definition
- Inherits:
-
Object
- Object
- FactoryGirl::Definition
- Defined in:
- lib/factory_girl/definition.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#defined_traits ⇒ Object
readonly
Returns the value of attribute defined_traits.
Instance Method Summary collapse
- #add_callback(callback) ⇒ Object
- #attributes ⇒ Object
- #compile ⇒ Object
- #define_trait(trait) ⇒ Object
- #inherit_traits(new_traits) ⇒ Object
-
#initialize(name = nil) ⇒ Definition
constructor
A new instance of Definition.
- #overridable ⇒ Object
- #to_create(&block) ⇒ Object
- #traits ⇒ Object
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
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
3 4 5 |
# File 'lib/factory_girl/definition.rb', line 3 def callbacks @callbacks end |
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
3 4 5 |
# File 'lib/factory_girl/definition.rb', line 3 def declarations @declarations end |
#defined_traits ⇒ Object (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 |
#attributes ⇒ Object
15 16 17 |
# File 'lib/factory_girl/definition.rb', line 15 def attributes @attributes ||= declarations.attribute_list end |
#compile ⇒ Object
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 |
#overridable ⇒ Object
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 |
#traits ⇒ Object
28 29 30 |
# File 'lib/factory_girl/definition.rb', line 28 def traits @traits.reverse.map { |name| trait_by_name(name) } end |