Class: FactoryGirl::Trait
- Inherits:
-
Object
- Object
- FactoryGirl::Trait
- Defined in:
- lib/factory_girl/trait.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_callback(name, &block) ⇒ Object
- #attributes ⇒ Object
- #declare_attribute(declaration) ⇒ Object
-
#initialize(name, &block) ⇒ Trait
constructor
:nodoc:.
- #names ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Trait
:nodoc:
5 6 7 8 9 10 11 |
# File 'lib/factory_girl/trait.rb', line 5 def initialize(name, &block) #:nodoc: @name = name @attribute_list = AttributeList.new proxy = FactoryGirl::DefinitionProxy.new(self) proxy.instance_eval(&block) if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/factory_girl/trait.rb', line 3 def name @name end |
Instance Method Details
#add_callback(name, &block) ⇒ Object
18 19 20 |
# File 'lib/factory_girl/trait.rb', line 18 def add_callback(name, &block) @attribute_list.add_callback(Callback.new(name, block)) end |
#attributes ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/factory_girl/trait.rb', line 22 def attributes AttributeList.new.tap do |list| @attribute_list.declarations.each do |declaration| declaration.to_attributes.each do |attribute| list.define_attribute(attribute) end end list.apply_attributes @attribute_list end end |
#declare_attribute(declaration) ⇒ Object
13 14 15 16 |
# File 'lib/factory_girl/trait.rb', line 13 def declare_attribute(declaration) @attribute_list.declare_attribute(declaration) declaration end |
#names ⇒ Object
33 34 35 |
# File 'lib/factory_girl/trait.rb', line 33 def names [@name] end |