Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7045 from kennyj/remove_duplicated_code_20120714

Remove duplicated code in the AR::Store.
  • Loading branch information...
commit fd9655c9dc9c96dc43cc6b22e64ec216db2fdfc0 2 parents bf6d64c + 6c7c89a
@rafaelfranca rafaelfranca authored
Showing with 3 additions and 11 deletions.
  1. +3 −11 activerecord/lib/active_record/store.rb
View
14 activerecord/lib/active_record/store.rb
@@ -77,16 +77,8 @@ def store_accessor(store_attribute, *keys)
private
def initialize_store_attribute(store_attribute)
- case attribute = send(store_attribute)
- when ActiveSupport::HashWithIndifferentAccess
- # Already initialized. Do nothing.
- when Hash
- # Initialized as a Hash. Convert to indifferent access.
- send :"#{store_attribute}=", attribute.with_indifferent_access
- else
- # Uninitialized. Set to an indifferent hash.
- send :"#{store_attribute}=", ActiveSupport::HashWithIndifferentAccess.new
- end
+ attr = send(store_attribute)
+ send :"#{store_attribute}=", IndifferentCoder.as_indifferent_hash(attr) unless attr.is_a?(HashWithIndifferentAccess)
end
class IndifferentCoder
@@ -109,7 +101,7 @@ def load(yaml)
def self.as_indifferent_hash(obj)
case obj
- when ActiveSupport::HashWithIndifferentAccess
+ when HashWithIndifferentAccess
obj
when Hash
obj.with_indifferent_access
Please sign in to comment.
Something went wrong with that request. Please try again.