Class: Factory::Attribute
- Inherits:
-
Object
- Object
- Factory::Attribute
- Defined in:
- lib/factory_girl/attribute.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, static_value, lazy_block) ⇒ Attribute
constructor
A new instance of Attribute.
- #value(proxy) ⇒ Object
Constructor Details
#initialize(name, static_value, lazy_block) ⇒ Attribute
Returns a new instance of Attribute.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/factory_girl/attribute.rb', line 10 def initialize (name, static_value, lazy_block) name = name.to_sym if name.to_s =~ /=$/ raise AttributeDefinitionError, "factory_girl uses 'f.#{name.to_s.chop} value' syntax " + "rather than 'f.#{name} = value'" end unless static_value.nil? || lazy_block.nil? raise AttributeDefinitionError, "Both value and block given" end @name = name @static_value = static_value @lazy_block = lazy_block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/factory_girl/attribute.rb', line 8 def name @name end |
Instance Method Details
#value(proxy) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/factory_girl/attribute.rb', line 28 def value (proxy) if @lazy_block.nil? @static_value else @lazy_block.call(proxy) end end |