Class: MultiJson::Adapter Private
- Inherits:
-
Object
- Object
- MultiJson::Adapter
- Extended by:
- Options
- Includes:
- Singleton
- Defined in:
- lib/multi_json/adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for JSON adapter implementations
Each adapter wraps a specific JSON library (Oj, JSON gem, etc.) and provides a consistent interface. Uses Singleton pattern so each adapter class has exactly one instance.
Subclasses must implement:
-
#load(string, options) -> parsed object
-
#dump(object, options) -> JSON string
Direct Known Subclasses
MultiJson::Adapters::FastJsonparser, MultiJson::Adapters::Gson, MultiJson::Adapters::JrJackson, MultiJson::Adapters::JsonGem, MultiJson::Adapters::Oj, MultiJson::Adapters::OkJson, MultiJson::Adapters::Yajl
Class Method Summary collapse
-
.defaults(action, value) ⇒ Hash
private
DSL for setting adapter-specific default options.
-
.dump(object, options = {}) ⇒ String
private
Serialize a Ruby object to JSON.
-
.inherited(subclass) ⇒ void
private
Hook called when a subclass is created.
-
.load(string, options = {}) ⇒ Object?
private
Parse a JSON string into a Ruby object.
Methods included from Options
default_dump_options, default_load_options, dump_options, dump_options=, load_options, load_options=
Class Method Details
.defaults(action, value) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
DSL for setting adapter-specific default options
42 43 44 |
# File 'lib/multi_json/adapter.rb', line 42 def defaults(action, value) instance_variable_set(:"@default_#{action}_options", value.freeze) end |
.dump(object, options = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize a Ruby object to JSON
65 66 67 |
# File 'lib/multi_json/adapter.rb', line 65 def dump(object, = {}) instance.dump(object, ()) end |
.inherited(subclass) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Hook called when a subclass is created
29 30 31 32 33 34 |
# File 'lib/multi_json/adapter.rb', line 29 def inherited(subclass) super # Propagate default options to subclasses subclass.instance_variable_set(:@default_load_options, ) if defined?() subclass.instance_variable_set(:@default_dump_options, ) if defined?() end |
.load(string, options = {}) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse a JSON string into a Ruby object
52 53 54 55 56 57 |
# File 'lib/multi_json/adapter.rb', line 52 def load(string, = {}) string = string.read if string.respond_to?(:read) return nil if blank?(string) instance.load(string, ()) end |