123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Store::IndifferentCoder

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/store.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(attr_name, coder_or_class_name) ⇒ IndifferentCoder

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 265

def initialize(attr_name, coder_or_class_name)
  @coder =
    if coder_or_class_name.respond_to?(:load) && coder_or_class_name.respond_to?(:dump)
      coder_or_class_name
    else
      ActiveRecord::Coders::YAMLColumn.new(attr_name, coder_or_class_name || Object)
    end
end

Class Method Details

.as_indifferent_hash(obj)

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 282

def self.as_indifferent_hash(obj)
  case obj
  when ActiveSupport::HashWithIndifferentAccess
    obj
  when Hash
    obj.with_indifferent_access
  else
    ActiveSupport::HashWithIndifferentAccess.new
  end
end

Instance Method Details

#as_regular_hash(obj) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 294

def as_regular_hash(obj)
  obj.respond_to?(:to_hash) ? obj.to_hash : {}
end

#dump(obj)

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 274

def dump(obj)
  @coder.dump as_regular_hash(obj)
end

#load(yaml)

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 278

def load(yaml)
  self.class.as_indifferent_hash(@coder.load(yaml || ""))
end