Class: ActiveRecord::Store::IndifferentCoder
- Inherits:
-
Object
- Object
- ActiveRecord::Store::IndifferentCoder
- Defined in:
- lib/active_record/store.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #dump(obj) ⇒ Object
-
#initialize(coder_or_class_name) ⇒ IndifferentCoder
constructor
A new instance of IndifferentCoder.
- #load(yaml) ⇒ Object
Constructor Details
#initialize(coder_or_class_name) ⇒ IndifferentCoder
Returns a new instance of IndifferentCoder.
181 182 183 184 185 186 187 188 |
# File 'lib/active_record/store.rb', line 181 def initialize(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(coder_or_class_name || Object) end end |
Class Method Details
.as_indifferent_hash(obj) ⇒ Object
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/active_record/store.rb', line 198 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
#dump(obj) ⇒ Object
190 191 192 |
# File 'lib/active_record/store.rb', line 190 def dump(obj) @coder.dump self.class.as_indifferent_hash(obj) end |
#load(yaml) ⇒ Object
194 195 196 |
# File 'lib/active_record/store.rb', line 194 def load(yaml) self.class.as_indifferent_hash(@coder.load(yaml || '')) end |