rufus-json 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/lib/rufus/json.rb +15 -5
- data/rufus-json.gemspec +2 -2
- data/test/test.rb +35 -0
- metadata +3 -3
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
= rufus-json CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-json - 0.2.3 released 2010/06/29
|
6
|
+
|
7
|
+
- made sure we're able to parse any JSON string
|
8
|
+
('json' couldn't parse "true", '"string"' or "12345" on their own)
|
9
|
+
|
10
|
+
|
5
11
|
== rufus-json - 0.2.2 released 2010/05/26
|
6
12
|
|
7
13
|
- Unified Rufus::Json::ParserError (Torsten Schoenebaum)
|
data/lib/rufus/json.rb
CHANGED
@@ -26,13 +26,13 @@
|
|
26
26
|
module Rufus
|
27
27
|
module Json
|
28
28
|
|
29
|
-
VERSION = '0.2.
|
29
|
+
VERSION = '0.2.3'
|
30
30
|
|
31
31
|
# The JSON / JSON pure decoder
|
32
32
|
#
|
33
33
|
JSON = [
|
34
34
|
lambda { |o| o.to_json },
|
35
|
-
lambda { |s| ::JSON.parse(s, :max_nesting => nil) },
|
35
|
+
lambda { |s| ::JSON.parse("[#{s}]", :max_nesting => nil).first },
|
36
36
|
lambda { ::JSON::ParserError }
|
37
37
|
]
|
38
38
|
|
@@ -40,8 +40,9 @@ module Json
|
|
40
40
|
#
|
41
41
|
ACTIVE_SUPPORT = [
|
42
42
|
lambda { |o| ActiveSupport::JSON.encode(o) },
|
43
|
-
lambda { |s| ActiveSupport::JSON.decode(s) },
|
44
|
-
lambda { ::ActiveSupport::JSON::ParseError }
|
43
|
+
lambda { |s| decode_e(s) || ActiveSupport::JSON.decode(s) },
|
44
|
+
#lambda { ::ActiveSupport::JSON::ParseError }
|
45
|
+
lambda { RuntimeError }
|
45
46
|
]
|
46
47
|
ACTIVE = ACTIVE_SUPPORT
|
47
48
|
|
@@ -55,7 +56,7 @@ module Json
|
|
55
56
|
|
56
57
|
# The "raise an exception because there's no backend" backend
|
57
58
|
#
|
58
|
-
NONE = [
|
59
|
+
NONE = [
|
59
60
|
lambda { |s| raise 'no JSON backend found' },
|
60
61
|
lambda { |s| raise 'no JSON backend found' },
|
61
62
|
lambda { raise 'no JSON backend found' }
|
@@ -135,6 +136,15 @@ module Json
|
|
135
136
|
(@backend == NONE) ? Marshal.load(Marshal.dump(o)) : decode(encode(o))
|
136
137
|
end
|
137
138
|
|
139
|
+
E_REGEX = /^\d+(\.\d+)?[eE][+-]?\d+$/
|
140
|
+
|
141
|
+
# Let's ActiveSupport do the E number notation.
|
142
|
+
#
|
143
|
+
def self.decode_e (s)
|
144
|
+
|
145
|
+
s.match(E_REGEX) ? eval(s) : false
|
146
|
+
end
|
147
|
+
|
138
148
|
# Wraps parser errors during decode
|
139
149
|
#
|
140
150
|
class ParserError < StandardError; end
|
data/rufus-json.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rufus-json}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux", "Torsten Schoenebaum"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-29}
|
13
13
|
s.description = %q{
|
14
14
|
One interface to various JSON ruby libs (yajl, json, json_pure, json-jruby, active_support). Has a preference for yajl.
|
15
15
|
}
|
data/test/test.rb
CHANGED
@@ -71,6 +71,11 @@ class JsonTest < Test::Unit::TestCase
|
|
71
71
|
do_test_parser_error('json', Rufus::Json::JSON)
|
72
72
|
end
|
73
73
|
|
74
|
+
def test_json_atoms_json
|
75
|
+
|
76
|
+
do_test_json_atoms('json', Rufus::Json::JSON)
|
77
|
+
end
|
78
|
+
|
74
79
|
def test_decode_yajl
|
75
80
|
|
76
81
|
do_test_decode('yajl', Rufus::Json::YAJL)
|
@@ -96,6 +101,11 @@ class JsonTest < Test::Unit::TestCase
|
|
96
101
|
do_test_parser_error('yajl', Rufus::Json::YAJL)
|
97
102
|
end
|
98
103
|
|
104
|
+
def test_json_atoms_yajl
|
105
|
+
|
106
|
+
do_test_json_atoms('yajl', Rufus::Json::YAJL)
|
107
|
+
end
|
108
|
+
|
99
109
|
def test_decode_as
|
100
110
|
|
101
111
|
do_test_decode('active_support', Rufus::Json::ACTIVE)
|
@@ -116,6 +126,11 @@ class JsonTest < Test::Unit::TestCase
|
|
116
126
|
do_test_deep_nesting('active_support', Rufus::Json::ACTIVE)
|
117
127
|
end
|
118
128
|
|
129
|
+
def test_json_atoms_as
|
130
|
+
|
131
|
+
do_test_json_atoms('active_support', Rufus::Json::ACTIVE)
|
132
|
+
end
|
133
|
+
|
119
134
|
protected
|
120
135
|
|
121
136
|
def do_test_decode (lib, cons)
|
@@ -184,5 +199,25 @@ class JsonTest < Test::Unit::TestCase
|
|
184
199
|
Rufus::Json.decode(s)
|
185
200
|
end
|
186
201
|
end
|
202
|
+
|
203
|
+
def do_test_json_atoms (lib, cons)
|
204
|
+
|
205
|
+
require lib
|
206
|
+
Rufus::Json.backend = cons
|
207
|
+
|
208
|
+
[
|
209
|
+
[ '1', 1 ],
|
210
|
+
[ '1.1', 1.1 ],
|
211
|
+
[ '1.1e10', 1.1e10 ],
|
212
|
+
[ '1.1E10', 1.1e10 ],
|
213
|
+
[ '1.1E-10', 1.1e-10 ],
|
214
|
+
[ '"a"', 'a' ],
|
215
|
+
[ 'true', true ],
|
216
|
+
[ 'false', false ],
|
217
|
+
[ 'null', nil ]
|
218
|
+
].each do |s, v|
|
219
|
+
assert_equal v, Rufus::Json.decode(s)
|
220
|
+
end
|
221
|
+
end
|
187
222
|
end
|
188
223
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mettraux
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-06-29 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|