Commit 526ced32 by Matthew Schulkind Committed by Jon Yurek

Stop caching instance variables that the instance stores itself.

Fixes #913.
parent de6af668
...@@ -321,19 +321,22 @@ module Paperclip ...@@ -321,19 +321,22 @@ module Paperclip
# "avatar_file_name" field (assuming the attachment is called avatar). # "avatar_file_name" field (assuming the attachment is called avatar).
def instance_write(attr, value) def instance_write(attr, value)
setter = :"#{name}_#{attr}=" setter = :"#{name}_#{attr}="
responds = instance.respond_to?(setter) if instance.respond_to?(setter)
instance.send(setter, value)
else
self.instance_variable_set("@_#{setter.to_s.chop}", value) self.instance_variable_set("@_#{setter.to_s.chop}", value)
instance.send(setter, value) if responds || attr.to_s == "file_name" end
end end
# Reads the attachment-specific attribute on the instance. See instance_write # Reads the attachment-specific attribute on the instance. See instance_write
# for more details. # for more details.
def instance_read(attr) def instance_read(attr)
getter = :"#{name}_#{attr}" getter = :"#{name}_#{attr}"
responds = instance.respond_to?(getter) if instance.respond_to?(getter)
cached = self.instance_variable_get("@_#{getter}") instance.send(getter)
return cached if cached else
instance.send(getter) if responds || attr.to_s == "file_name" self.instance_variable_get("@_#{getter}")
end
end end
private private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment