Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoid to call send(store_attribute) twice.

  • Loading branch information...
commit 088022ef262cc43318651cf7bd68e6eb4b5475f6 1 parent 9b7401b
@kennyj kennyj authored
Showing with 8 additions and 6 deletions.
  1. +8 −6 activerecord/lib/active_record/store.rb
View
14 activerecord/lib/active_record/store.rb
@@ -57,8 +57,7 @@ def store_accessor(store_attribute, *keys)
keys = keys.flatten
keys.each do |key|
define_method("#{key}=") do |value|
- initialize_store_attribute(store_attribute)
- attribute = send(store_attribute)
+ attribute = initialize_store_attribute(store_attribute)
if value != attribute[key]
attribute[key] = value
send :"#{store_attribute}_will_change!"
@@ -66,8 +65,7 @@ def store_accessor(store_attribute, *keys)
end
define_method(key) do
- initialize_store_attribute(store_attribute)
- send(store_attribute)[key]
+ initialize_store_attribute(store_attribute)[key]
end
end
@@ -77,8 +75,12 @@ def store_accessor(store_attribute, *keys)
private
def initialize_store_attribute(store_attribute)
- attr = send(store_attribute)
- send :"#{store_attribute}=", IndifferentCoder.as_indifferent_hash(attr) unless attr.is_a?(HashWithIndifferentAccess)
+ attribute = send(store_attribute)
+ unless attribute.is_a?(HashWithIndifferentAccess)
+ attribute = IndifferentCoder.as_indifferent_hash(attribute)
+ send :"#{store_attribute}=", attribute
+ end
+ attribute
end
class IndifferentCoder
Please sign in to comment.
Something went wrong with that request. Please try again.