Class: MultiJson::Adapters::JsonCommon
Constant Summary
collapse
- GEM_VERSION =
'1.7.7'
Instance Attribute Summary
Attributes included from Options
#dump_options, #load_options
Instance Method Summary
collapse
activate!, defaults, dump, load
Methods included from Options
#default_dump_options, #default_load_options
Instance Method Details
#activate ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/multi_json/adapters/json_common.rb', line 10
def activate
if JSON::VERSION < GEM_VERSION
Kernel.warn "You are using an old or stdlib version of #{gem_name} gem\n" +
"Please upgrade to the recent version by adding this to your Gemfile:\n\n" +
" gem '#{gem_name}', '~> #{GEM_VERSION}'\n"
end
end
|
#dump(object, options = {}) ⇒ Object
29
30
31
32
|
# File 'lib/multi_json/adapters/json_common.rb', line 29
def dump(object, options={})
options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
object.to_json(options)
end
|
#load(string, options = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/multi_json/adapters/json_common.rb', line 18
def load(string, options={})
string = string.read if string.respond_to?(:read)
if string.respond_to?(:force_encoding)
string = string.dup.force_encoding(::Encoding::ASCII_8BIT)
end
options[:symbolize_names] = true if options.delete(:symbolize_keys)
::JSON.parse(string, options)
end
|