Class: NoBrainer::Document::Store::IndifferentCoder
- Inherits:
-
Object
- Object
- NoBrainer::Document::Store::IndifferentCoder
- Defined in:
- lib/no_brainer/document/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.
274 275 276 277 278 279 280 281 |
# File 'lib/no_brainer/document/store.rb', line 274 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 NoBrainer::Document::Coders::YAMLColumn.new(attr_name, coder_or_class_name || Object) end end |
Class Method Details
.as_indifferent_hash(obj) ⇒ Object
291 292 293 294 295 296 297 298 299 300 |
# File 'lib/no_brainer/document/store.rb', line 291 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
283 284 285 |
# File 'lib/no_brainer/document/store.rb', line 283 def dump(obj) @coder.dump self.class.as_indifferent_hash(obj) end |
#load(yaml) ⇒ Object
287 288 289 |
# File 'lib/no_brainer/document/store.rb', line 287 def load(yaml) self.class.as_indifferent_hash(@coder.load(yaml || "")) end |