json 2.6.2 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/BSDL +22 -0
- data/CHANGES.md +144 -17
- data/LEGAL +8 -0
- data/README.md +67 -224
- data/ext/json/ext/fbuffer/fbuffer.h +110 -92
- data/ext/json/ext/generator/extconf.rb +8 -2
- data/ext/json/ext/generator/generator.c +1020 -806
- data/ext/json/ext/parser/extconf.rb +7 -27
- data/ext/json/ext/parser/parser.c +1343 -3212
- data/json.gemspec +48 -52
- data/lib/json/add/bigdecimal.rb +39 -10
- data/lib/json/add/complex.rb +29 -6
- data/lib/json/add/core.rb +1 -1
- data/lib/json/add/date.rb +27 -7
- data/lib/json/add/date_time.rb +26 -9
- data/lib/json/add/exception.rb +25 -7
- data/lib/json/add/ostruct.rb +32 -9
- data/lib/json/add/range.rb +33 -8
- data/lib/json/add/rational.rb +28 -6
- data/lib/json/add/regexp.rb +26 -8
- data/lib/json/add/set.rb +25 -6
- data/lib/json/add/struct.rb +29 -7
- data/lib/json/add/symbol.rb +34 -7
- data/lib/json/add/time.rb +29 -15
- data/lib/json/common.rb +418 -128
- data/lib/json/ext/generator/state.rb +106 -0
- data/lib/json/ext.rb +34 -4
- data/lib/json/generic_object.rb +7 -3
- data/lib/json/truffle_ruby/generator.rb +690 -0
- data/lib/json/version.rb +3 -7
- data/lib/json.rb +25 -21
- metadata +15 -26
- data/VERSION +0 -1
- data/ext/json/ext/generator/depend +0 -1
- data/ext/json/ext/generator/generator.h +0 -174
- data/ext/json/ext/parser/depend +0 -1
- data/ext/json/ext/parser/parser.h +0 -96
- data/ext/json/ext/parser/parser.rl +0 -986
- data/ext/json/extconf.rb +0 -3
- data/lib/json/pure/generator.rb +0 -479
- data/lib/json/pure/parser.rb +0 -337
- data/lib/json/pure.rb +0 -15
- /data/{LICENSE → COPYING} +0 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
module Ext
|
5
|
+
module Generator
|
6
|
+
class State
|
7
|
+
# call-seq: new(opts = {})
|
8
|
+
#
|
9
|
+
# Instantiates a new State object, configured by _opts_.
|
10
|
+
#
|
11
|
+
# _opts_ can have the following keys:
|
12
|
+
#
|
13
|
+
# * *indent*: a string used to indent levels (default: ''),
|
14
|
+
# * *space*: a string that is put after, a : or , delimiter (default: ''),
|
15
|
+
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
|
16
|
+
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
17
|
+
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
|
18
|
+
# * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
19
|
+
# generated, otherwise an exception is thrown, if these values are
|
20
|
+
# encountered. This options defaults to false.
|
21
|
+
# * *ascii_only*: true if only ASCII characters should be generated. This
|
22
|
+
# option defaults to false.
|
23
|
+
# * *buffer_initial_length*: sets the initial length of the generator's
|
24
|
+
# internal buffer.
|
25
|
+
def initialize(opts = nil)
|
26
|
+
if opts && !opts.empty?
|
27
|
+
configure(opts)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# call-seq: configure(opts)
|
32
|
+
#
|
33
|
+
# Configure this State instance with the Hash _opts_, and return
|
34
|
+
# itself.
|
35
|
+
def configure(opts)
|
36
|
+
unless opts.is_a?(Hash)
|
37
|
+
if opts.respond_to?(:to_hash)
|
38
|
+
opts = opts.to_hash
|
39
|
+
elsif opts.respond_to?(:to_h)
|
40
|
+
opts = opts.to_h
|
41
|
+
else
|
42
|
+
raise TypeError, "can't convert #{opts.class} into Hash"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
_configure(opts)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :merge, :configure
|
49
|
+
|
50
|
+
# call-seq: to_h
|
51
|
+
#
|
52
|
+
# Returns the configuration instance variables as a hash, that can be
|
53
|
+
# passed to the configure method.
|
54
|
+
def to_h
|
55
|
+
result = {
|
56
|
+
indent: indent,
|
57
|
+
space: space,
|
58
|
+
space_before: space_before,
|
59
|
+
object_nl: object_nl,
|
60
|
+
array_nl: array_nl,
|
61
|
+
as_json: as_json,
|
62
|
+
allow_nan: allow_nan?,
|
63
|
+
ascii_only: ascii_only?,
|
64
|
+
max_nesting: max_nesting,
|
65
|
+
script_safe: script_safe?,
|
66
|
+
strict: strict?,
|
67
|
+
depth: depth,
|
68
|
+
buffer_initial_length: buffer_initial_length,
|
69
|
+
}
|
70
|
+
|
71
|
+
instance_variables.each do |iv|
|
72
|
+
iv = iv.to_s[1..-1]
|
73
|
+
result[iv.to_sym] = self[iv]
|
74
|
+
end
|
75
|
+
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
alias_method :to_hash, :to_h
|
80
|
+
|
81
|
+
# call-seq: [](name)
|
82
|
+
#
|
83
|
+
# Returns the value returned by method +name+.
|
84
|
+
def [](name)
|
85
|
+
if respond_to?(name)
|
86
|
+
__send__(name)
|
87
|
+
else
|
88
|
+
instance_variable_get("@#{name}") if
|
89
|
+
instance_variables.include?("@#{name}".to_sym) # avoid warning
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# call-seq: []=(name, value)
|
94
|
+
#
|
95
|
+
# Sets the attribute name to value.
|
96
|
+
def []=(name, value)
|
97
|
+
if respond_to?(name_writer = "#{name}=")
|
98
|
+
__send__ name_writer, value
|
99
|
+
else
|
100
|
+
instance_variable_set "@#{name}", value
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/json/ext.rb
CHANGED
@@ -1,14 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json/common'
|
2
4
|
|
3
5
|
module JSON
|
4
6
|
# This module holds all the modules/classes that implement JSON's
|
5
7
|
# functionality as C extensions.
|
6
8
|
module Ext
|
9
|
+
class Parser
|
10
|
+
class << self
|
11
|
+
def parse(...)
|
12
|
+
new(...).parse
|
13
|
+
end
|
14
|
+
alias_method :parse, :parse # Allow redefinition by extensions
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(source, opts = nil)
|
18
|
+
@source = source
|
19
|
+
@config = Config.new(opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def source
|
23
|
+
@source.dup
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse
|
27
|
+
@config.parse(@source)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
7
31
|
require 'json/ext/parser'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
32
|
+
Ext::Parser::Config = Ext::ParserConfig
|
33
|
+
JSON.parser = Ext::Parser
|
34
|
+
|
35
|
+
if RUBY_ENGINE == 'truffleruby'
|
36
|
+
require 'json/truffle_ruby/generator'
|
37
|
+
JSON.generator = ::JSON::TruffleRuby::Generator
|
38
|
+
else
|
39
|
+
require 'json/ext/generator'
|
40
|
+
JSON.generator = Generator
|
41
|
+
end
|
12
42
|
end
|
13
43
|
|
14
44
|
JSON_LOADED = true unless defined?(::JSON::JSON_LOADED)
|
data/lib/json/generic_object.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
#frozen_string_literal:
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
begin
|
3
|
+
require 'ostruct'
|
4
|
+
rescue LoadError
|
5
|
+
warn "JSON::GenericObject requires 'ostruct'. Please install it with `gem install ostruct`."
|
6
|
+
end
|
3
7
|
|
4
8
|
module JSON
|
5
9
|
class GenericObject < OpenStruct
|
@@ -67,5 +71,5 @@ module JSON
|
|
67
71
|
def to_json(*a)
|
68
72
|
as_json.to_json(*a)
|
69
73
|
end
|
70
|
-
end
|
74
|
+
end if defined?(::OpenStruct)
|
71
75
|
end
|