Class: ActiveEntity::Store::IndifferentCoder
- Inherits:
-
Object
- Object
- ActiveEntity::Store::IndifferentCoder
- Defined in:
- lib/active_entity/store.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #dump(obj) ⇒ Object
-
#initialize(attr_name, coder_or_class_name) ⇒ IndifferentCoder
constructor
A new instance of IndifferentCoder.
- #load(yaml) ⇒ Object
Constructor Details
#initialize(attr_name, coder_or_class_name) ⇒ IndifferentCoder
Returns a new instance of IndifferentCoder.
262 263 264 265 266 267 268 269 |
# File 'lib/active_entity/store.rb', line 262 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 ActiveEntity::Coders::YAMLColumn.new(attr_name, coder_or_class_name || Object) end end |
Class Method Details
.as_indifferent_hash(obj) ⇒ Object
279 280 281 282 283 284 285 286 287 288 |
# File 'lib/active_entity/store.rb', line 279 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
271 272 273 |
# File 'lib/active_entity/store.rb', line 271 def dump(obj) @coder.dump self.class.as_indifferent_hash(obj) end |
#load(yaml) ⇒ Object
275 276 277 |
# File 'lib/active_entity/store.rb', line 275 def load(yaml) self.class.as_indifferent_hash(@coder.load(yaml || "")) end |