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::JsonGem, MultiJSON::Adapters::Oj, MultiJSON::Adapters::Yajl
Constant Summary
Constants included from Options
Class Method Summary collapse
-
.default_dump_options ⇒ Hash
deprecated
private
Deprecated.
Use Adapter.default_generate_options instead. Will be removed in v2.0.
-
.default_generate_options ⇒ Hash
private
Get default generate options, walking the superclass chain.
-
.default_load_options ⇒ Hash
deprecated
private
Deprecated.
Use Adapter.default_parse_options instead. Will be removed in v2.0.
-
.default_parse_options ⇒ Hash
private
Get default parse options, walking the superclass chain.
-
.defaults(action, value) ⇒ Hash
private
DSL for setting adapter-specific default options.
-
.dump(object, options = {}) ⇒ String
private
Serialize a Ruby object to JSON.
-
.load(string, options = {}) ⇒ Object?
private
Parse a JSON string into a Ruby object.
Methods included from Options
default_dump_options, default_generate_options, default_load_options, default_parse_options, dump_options, dump_options=, generate_options, generate_options=, load_options, load_options=, parse_options, parse_options=
Class Method Details
.default_dump_options ⇒ 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.
Use default_generate_options instead. Will be removed in v2.0.
Get default generate options, walking the superclass chain
62 63 64 |
# File 'lib/multi_json/adapter.rb', line 62 def end |
.default_generate_options ⇒ 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.
Get default generate options, walking the superclass chain
44 45 46 |
# File 'lib/multi_json/adapter.rb', line 44 def (:@default_dump_options) end |
.default_load_options ⇒ 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.
Use default_parse_options instead. Will be removed in v2.0.
Get default parse options, walking the superclass chain
53 54 55 |
# File 'lib/multi_json/adapter.rb', line 53 def end |
.default_parse_options ⇒ 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.
Get default parse options, walking the superclass chain
Returns the closest ancestor’s ‘@default_load_options` ivar so a parent class calling defaults after a subclass has been defined still propagates to the subclass. Falls back to the shared frozen empty hash when no ancestor has defaults set.
36 37 38 |
# File 'lib/multi_json/adapter.rb', line 36 def (:@default_load_options) end |
.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
“action“ must be “:load“ or “:dump“; “value“ must be a Hash. Both arguments are validated up front so a typo at the adapter’s class definition fails fast instead of producing a silent no-op default that crashes later in the merge path.
83 84 85 86 87 88 |
# File 'lib/multi_json/adapter.rb', line 83 def defaults(action, value) raise ArgumentError, "expected action to be :load or :dump, got #{action.inspect}" unless VALID_DEFAULTS_ACTIONS.include?(action) raise ArgumentError, "expected value to be a Hash, got #{value.class}" unless value.is_a?(Hash) 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
109 110 111 |
# File 'lib/multi_json/adapter.rb', line 109 def dump(object, = {}) instance.dump(object, ()) 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
96 97 98 99 100 101 |
# File 'lib/multi_json/adapter.rb', line 96 def load(string, = {}) string = string.read if string.respond_to?(:read) return nil if blank?(string) instance.load(string, ()) end |