Class: FactoryGirl::Proxy::ObjectWrapper

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

Instance Method Summary collapse

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

#objectObject



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_hashObject



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