Class: FactoryGirl::Proxy::ObjectWrapper
- Inherits:
-
Object
- Object
- FactoryGirl::Proxy::ObjectWrapper
- Defined in:
- lib/factory_girl/proxy.rb
Instance Method Summary collapse
- #get(attribute) ⇒ Object
-
#initialize(klass) ⇒ ObjectWrapper
constructor
A new instance of ObjectWrapper.
- #object ⇒ Object
- #set(attribute, value) ⇒ Object
- #set_ignored(attribute, value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(klass) ⇒ ObjectWrapper
Returns a new instance of ObjectWrapper.
92 93 94 95 96 |
# File 'lib/factory_girl/proxy.rb', line 92 def initialize(klass) @klass = klass @attributes = [] @cached_attribute_values = {} end |
Instance Method Details
#get(attribute) ⇒ Object
120 121 122 |
# File 'lib/factory_girl/proxy.rb', line 120 def get(attribute) @cached_attribute_values[attribute] ||= anonymous_instance.send(attribute) end |
#object ⇒ Object
105 106 107 108 109 |
# File 'lib/factory_girl/proxy.rb', line 105 def object @object ||= @klass.new assign_object_attributes @object end |
#set(attribute, value) ⇒ Object
111 112 113 114 |
# File 'lib/factory_girl/proxy.rb', line 111 def set(attribute, value) define_attribute(attribute, value) @attributes << attribute.name end |
#set_ignored(attribute, value) ⇒ Object
116 117 118 |
# File 'lib/factory_girl/proxy.rb', line 116 def set_ignored(attribute, value) define_attribute(attribute, value) end |
#to_hash ⇒ Object
98 99 100 101 102 103 |
# File 'lib/factory_girl/proxy.rb', line 98 def to_hash @attributes.inject({}) do |result, attribute| result[attribute] = get(attribute) result end end |