summaryrefslogtreecommitdiff
path: root/lib/json
diff options
context:
space:
mode:
Diffstat (limited to 'lib/json')
-rw-r--r--lib/json/add/core.rb9
-rw-r--r--lib/json/common.rb17
-rw-r--r--lib/json/pure/parser.rb8
-rw-r--r--lib/json/version.rb2
4 files changed, 23 insertions, 13 deletions
diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb
index 1ae00d0..01b8e04 100644
--- a/lib/json/add/core.rb
+++ b/lib/json/add/core.rb
@@ -36,8 +36,8 @@ class Time
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
object['n'] = usec * 1000
end
- if respond_to?(:tv_nsec)
- at(*object.values_at('s', 'n'))
+ if instance_methods.include?(:tv_nsec)
+ at(object['s'], Rational(object['n'], 1000))
else
at(object['s'], object['n'] / 1000)
end
@@ -46,10 +46,13 @@ class Time
# Returns a hash, that will be turned into a JSON object and represent this
# object.
def as_json(*)
+ nanoseconds = [ tv_usec * 1000 ]
+ respond_to?(:tv_nsec) and nanoseconds << tv_nsec
+ nanoseconds = nanoseconds.max
{
JSON.create_id => self.class.name,
's' => tv_sec,
- 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
+ 'n' => nanoseconds,
}
end
diff --git a/lib/json/common.rb b/lib/json/common.rb
index 43e249c..9ad1fab 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -141,7 +141,7 @@ module JSON
# the default.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matching class and create_id was found. This option
- # defaults to true.
+ # defaults to false.
# * *object_class*: Defaults to Hash
# * *array_class*: Defaults to Array
def parse(source, opts = {})
@@ -162,7 +162,7 @@ module JSON
# to true.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matching class and create_id was found. This option
- # defaults to true.
+ # defaults to false.
def parse!(source, opts = {})
opts = {
:max_nesting => false,
@@ -287,11 +287,18 @@ module JSON
# Load a ruby data structure from a JSON _source_ and return it. A source can
# either be a string-like object, an IO-like object, or an object responding
# to the read method. If _proc_ was given, it will be called with any nested
- # Ruby object as an argument recursively in depth first order.
+ # Ruby object as an argument recursively in depth first order. To modify the
+ # default options pass in the optional _options_ argument as well.
#
# This method is part of the implementation of the load/dump interface of
# Marshal and YAML.
- def load(source, proc = nil)
+ def load(source, proc = nil, options = {})
+ load_default_options = {
+ :max_nesting => false,
+ :allow_nan => true,
+ :create_additions => false
+ }
+ opts = load_default_options.merge options
if source.respond_to? :to_str
source = source.to_str
elsif source.respond_to? :to_io
@@ -299,7 +306,7 @@ module JSON
else
source = source.read
end
- result = parse(source, :max_nesting => false, :allow_nan => true)
+ result = parse(source, opts)
recurse_proc(result, &proc) if proc
result
end
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index e24aac1..d02ec34 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -63,9 +63,9 @@ module JSON
# * *symbolize_names*: If set to true, returns symbols for the names
# (keys) in a JSON object. Otherwise strings are returned, which is also
# the default.
- # * *create_additions*: If set to false, the Parser doesn't create
- # additions even if a matchin class and create_id was found. This option
- # defaults to true.
+ # * *create_additions*: If set to true, the Parser creates
+ # additions when if a matching class and create_id was found. This
+ # option defaults to false.
# * *object_class*: Defaults to Hash
# * *array_class*: Defaults to Array
# * *quirks_mode*: Enables quirks_mode for parser, that is for example
@@ -88,7 +88,7 @@ module JSON
if opts.key?(:create_additions)
@create_additions = !!opts[:create_additions]
else
- @create_additions = true
+ @create_additions = false
end
@create_id = @create_additions ? JSON.create_id : nil
@object_class = opts[:object_class] || Hash
diff --git a/lib/json/version.rb b/lib/json/version.rb
index 2175ac0..baacdc9 100644
--- a/lib/json/version.rb
+++ b/lib/json/version.rb
@@ -1,6 +1,6 @@
module JSON
# JSON version
- VERSION = '1.5.4'
+ VERSION = '1.5.5'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: