json_pure 2.7.6 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -2
- data/README.md +8 -53
- data/json_pure.gemspec +19 -38
- data/lib/json/pure.rb +2 -14
- metadata +3 -24
- data/lib/json/add/bigdecimal.rb +0 -58
- data/lib/json/add/complex.rb +0 -51
- data/lib/json/add/core.rb +0 -12
- data/lib/json/add/date.rb +0 -54
- data/lib/json/add/date_time.rb +0 -67
- data/lib/json/add/exception.rb +0 -49
- data/lib/json/add/ostruct.rb +0 -54
- data/lib/json/add/range.rb +0 -54
- data/lib/json/add/rational.rb +0 -49
- data/lib/json/add/regexp.rb +0 -48
- data/lib/json/add/set.rb +0 -48
- data/lib/json/add/struct.rb +0 -52
- data/lib/json/add/symbol.rb +0 -47
- data/lib/json/add/time.rb +0 -52
- data/lib/json/common.rb +0 -734
- data/lib/json/ext.rb +0 -25
- data/lib/json/generic_object.rb +0 -75
- data/lib/json/pure/generator.rb +0 -599
- data/lib/json/pure/parser.rb +0 -331
- data/lib/json/version.rb +0 -5
- data/lib/json.rb +0 -592
data/lib/json/add/rational.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
-
require 'json'
|
4
|
-
end
|
5
|
-
|
6
|
-
class Rational
|
7
|
-
|
8
|
-
# See #as_json.
|
9
|
-
def self.json_create(object)
|
10
|
-
Rational(object['n'], object['d'])
|
11
|
-
end
|
12
|
-
|
13
|
-
# Methods <tt>Rational#as_json</tt> and +Rational.json_create+ may be used
|
14
|
-
# to serialize and deserialize a \Rational object;
|
15
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
-
#
|
17
|
-
# \Method <tt>Rational#as_json</tt> serializes +self+,
|
18
|
-
# returning a 2-element hash representing +self+:
|
19
|
-
#
|
20
|
-
# require 'json/add/rational'
|
21
|
-
# x = Rational(2, 3).as_json
|
22
|
-
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
23
|
-
#
|
24
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Rational object:
|
25
|
-
#
|
26
|
-
# Rational.json_create(x)
|
27
|
-
# # => (2/3)
|
28
|
-
#
|
29
|
-
def as_json(*)
|
30
|
-
{
|
31
|
-
JSON.create_id => self.class.name,
|
32
|
-
'n' => numerator,
|
33
|
-
'd' => denominator,
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns a JSON string representing +self+:
|
38
|
-
#
|
39
|
-
# require 'json/add/rational'
|
40
|
-
# puts Rational(2, 3).to_json
|
41
|
-
#
|
42
|
-
# Output:
|
43
|
-
#
|
44
|
-
# {"json_class":"Rational","n":2,"d":3}
|
45
|
-
#
|
46
|
-
def to_json(*args)
|
47
|
-
as_json.to_json(*args)
|
48
|
-
end
|
49
|
-
end
|
data/lib/json/add/regexp.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
-
require 'json'
|
4
|
-
end
|
5
|
-
|
6
|
-
class Regexp
|
7
|
-
|
8
|
-
# See #as_json.
|
9
|
-
def self.json_create(object)
|
10
|
-
new(object['s'], object['o'])
|
11
|
-
end
|
12
|
-
|
13
|
-
# Methods <tt>Regexp#as_json</tt> and +Regexp.json_create+ may be used
|
14
|
-
# to serialize and deserialize a \Regexp object;
|
15
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
-
#
|
17
|
-
# \Method <tt>Regexp#as_json</tt> serializes +self+,
|
18
|
-
# returning a 2-element hash representing +self+:
|
19
|
-
#
|
20
|
-
# require 'json/add/regexp'
|
21
|
-
# x = /foo/.as_json
|
22
|
-
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
23
|
-
#
|
24
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Regexp object:
|
25
|
-
#
|
26
|
-
# Regexp.json_create(x) # => /foo/
|
27
|
-
#
|
28
|
-
def as_json(*)
|
29
|
-
{
|
30
|
-
JSON.create_id => self.class.name,
|
31
|
-
'o' => options,
|
32
|
-
's' => source,
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
# Returns a JSON string representing +self+:
|
37
|
-
#
|
38
|
-
# require 'json/add/regexp'
|
39
|
-
# puts /foo/.to_json
|
40
|
-
#
|
41
|
-
# Output:
|
42
|
-
#
|
43
|
-
# {"json_class":"Regexp","o":0,"s":"foo"}
|
44
|
-
#
|
45
|
-
def to_json(*args)
|
46
|
-
as_json.to_json(*args)
|
47
|
-
end
|
48
|
-
end
|
data/lib/json/add/set.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
-
require 'json'
|
3
|
-
end
|
4
|
-
defined?(::Set) or require 'set'
|
5
|
-
|
6
|
-
class Set
|
7
|
-
|
8
|
-
# See #as_json.
|
9
|
-
def self.json_create(object)
|
10
|
-
new object['a']
|
11
|
-
end
|
12
|
-
|
13
|
-
# Methods <tt>Set#as_json</tt> and +Set.json_create+ may be used
|
14
|
-
# to serialize and deserialize a \Set object;
|
15
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
-
#
|
17
|
-
# \Method <tt>Set#as_json</tt> serializes +self+,
|
18
|
-
# returning a 2-element hash representing +self+:
|
19
|
-
#
|
20
|
-
# require 'json/add/set'
|
21
|
-
# x = Set.new(%w/foo bar baz/).as_json
|
22
|
-
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
23
|
-
#
|
24
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Set object:
|
25
|
-
#
|
26
|
-
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
27
|
-
#
|
28
|
-
def as_json(*)
|
29
|
-
{
|
30
|
-
JSON.create_id => self.class.name,
|
31
|
-
'a' => to_a,
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns a JSON string representing +self+:
|
36
|
-
#
|
37
|
-
# require 'json/add/set'
|
38
|
-
# puts Set.new(%w/foo bar baz/).to_json
|
39
|
-
#
|
40
|
-
# Output:
|
41
|
-
#
|
42
|
-
# {"json_class":"Set","a":["foo","bar","baz"]}
|
43
|
-
#
|
44
|
-
def to_json(*args)
|
45
|
-
as_json.to_json(*args)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
data/lib/json/add/struct.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
-
require 'json'
|
4
|
-
end
|
5
|
-
|
6
|
-
class Struct
|
7
|
-
|
8
|
-
# See #as_json.
|
9
|
-
def self.json_create(object)
|
10
|
-
new(*object['v'])
|
11
|
-
end
|
12
|
-
|
13
|
-
# Methods <tt>Struct#as_json</tt> and +Struct.json_create+ may be used
|
14
|
-
# to serialize and deserialize a \Struct object;
|
15
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
-
#
|
17
|
-
# \Method <tt>Struct#as_json</tt> serializes +self+,
|
18
|
-
# returning a 2-element hash representing +self+:
|
19
|
-
#
|
20
|
-
# require 'json/add/struct'
|
21
|
-
# Customer = Struct.new('Customer', :name, :address, :zip)
|
22
|
-
# x = Struct::Customer.new.as_json
|
23
|
-
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
24
|
-
#
|
25
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Struct object:
|
26
|
-
#
|
27
|
-
# Struct::Customer.json_create(x)
|
28
|
-
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
29
|
-
#
|
30
|
-
def as_json(*)
|
31
|
-
klass = self.class.name
|
32
|
-
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
33
|
-
{
|
34
|
-
JSON.create_id => klass,
|
35
|
-
'v' => values,
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
# Returns a JSON string representing +self+:
|
40
|
-
#
|
41
|
-
# require 'json/add/struct'
|
42
|
-
# Customer = Struct.new('Customer', :name, :address, :zip)
|
43
|
-
# puts Struct::Customer.new.to_json
|
44
|
-
#
|
45
|
-
# Output:
|
46
|
-
#
|
47
|
-
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
48
|
-
#
|
49
|
-
def to_json(*args)
|
50
|
-
as_json.to_json(*args)
|
51
|
-
end
|
52
|
-
end
|
data/lib/json/add/symbol.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
-
require 'json'
|
4
|
-
end
|
5
|
-
|
6
|
-
class Symbol
|
7
|
-
|
8
|
-
# Methods <tt>Symbol#as_json</tt> and +Symbol.json_create+ may be used
|
9
|
-
# to serialize and deserialize a \Symbol object;
|
10
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
11
|
-
#
|
12
|
-
# \Method <tt>Symbol#as_json</tt> serializes +self+,
|
13
|
-
# returning a 2-element hash representing +self+:
|
14
|
-
#
|
15
|
-
# require 'json/add/symbol'
|
16
|
-
# x = :foo.as_json
|
17
|
-
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
18
|
-
#
|
19
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Symbol object:
|
20
|
-
#
|
21
|
-
# Symbol.json_create(x) # => :foo
|
22
|
-
#
|
23
|
-
def as_json(*)
|
24
|
-
{
|
25
|
-
JSON.create_id => self.class.name,
|
26
|
-
's' => to_s,
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns a JSON string representing +self+:
|
31
|
-
#
|
32
|
-
# require 'json/add/symbol'
|
33
|
-
# puts :foo.to_json
|
34
|
-
#
|
35
|
-
# Output:
|
36
|
-
#
|
37
|
-
# # {"json_class":"Symbol","s":"foo"}
|
38
|
-
#
|
39
|
-
def to_json(*a)
|
40
|
-
as_json.to_json(*a)
|
41
|
-
end
|
42
|
-
|
43
|
-
# See #as_json.
|
44
|
-
def self.json_create(o)
|
45
|
-
o['s'].to_sym
|
46
|
-
end
|
47
|
-
end
|
data/lib/json/add/time.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
-
require 'json'
|
4
|
-
end
|
5
|
-
|
6
|
-
class Time
|
7
|
-
|
8
|
-
# See #as_json.
|
9
|
-
def self.json_create(object)
|
10
|
-
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
11
|
-
object['n'] = usec * 1000
|
12
|
-
end
|
13
|
-
at(object['s'], Rational(object['n'], 1000))
|
14
|
-
end
|
15
|
-
|
16
|
-
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
|
17
|
-
# to serialize and deserialize a \Time object;
|
18
|
-
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
19
|
-
#
|
20
|
-
# \Method <tt>Time#as_json</tt> serializes +self+,
|
21
|
-
# returning a 2-element hash representing +self+:
|
22
|
-
#
|
23
|
-
# require 'json/add/time'
|
24
|
-
# x = Time.now.as_json
|
25
|
-
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
26
|
-
#
|
27
|
-
# \Method +JSON.create+ deserializes such a hash, returning a \Time object:
|
28
|
-
#
|
29
|
-
# Time.json_create(x)
|
30
|
-
# # => 2023-11-25 11:00:56.472846644 -0600
|
31
|
-
#
|
32
|
-
def as_json(*)
|
33
|
-
{
|
34
|
-
JSON.create_id => self.class.name,
|
35
|
-
's' => tv_sec,
|
36
|
-
'n' => tv_nsec,
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a JSON string representing +self+:
|
41
|
-
#
|
42
|
-
# require 'json/add/time'
|
43
|
-
# puts Time.now.to_json
|
44
|
-
#
|
45
|
-
# Output:
|
46
|
-
#
|
47
|
-
# {"json_class":"Time","s":1700931678,"n":980650786}
|
48
|
-
#
|
49
|
-
def to_json(*args)
|
50
|
-
as_json.to_json(*args)
|
51
|
-
end
|
52
|
-
end
|