multi_json 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.travis.yml +2 -1
- data/.yardopts +6 -0
- data/CHANGELOG.md +116 -0
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +28 -4
- data/LICENSE.md +1 -1
- data/README.md +31 -15
- data/Rakefile +2 -10
- data/lib/multi_json.rb +113 -106
- data/lib/multi_json/adapters/gson.rb +20 -0
- data/lib/multi_json/adapters/json_common.rb +18 -8
- data/lib/multi_json/adapters/json_gem.rb +1 -1
- data/lib/multi_json/adapters/json_pure.rb +1 -1
- data/lib/multi_json/adapters/nsjsonserialization.rb +4 -3
- data/lib/multi_json/adapters/oj.rb +9 -7
- data/lib/multi_json/adapters/ok_json.rb +22 -12
- data/lib/multi_json/adapters/yajl.rb +5 -3
- data/lib/multi_json/version.rb +1 -1
- data/multi_json.gemspec +20 -21
- data/spec/adapter_shared_example.rb +55 -20
- data/spec/helper.rb +20 -14
- data/spec/json_common_shared_example.rb +34 -0
- data/spec/multi_json_spec.rb +57 -24
- metadata +44 -61
- metadata.gz.sig +0 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
shared_examples_for 'JSON-like adapter' do |adapter|
|
2
|
+
before do
|
3
|
+
begin
|
4
|
+
MultiJson.use adapter
|
5
|
+
rescue LoadError
|
6
|
+
pending "Adapter #{adapter} couldn't be loaded (not installed?)"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.dump' do
|
11
|
+
describe 'with :pretty option set to true' do
|
12
|
+
it 'passes default pretty options' do
|
13
|
+
::JSON.should_receive(:generate).with(['foo'], JSON::PRETTY_STATE_PROTOTYPE.to_h).and_return('["foo"]')
|
14
|
+
MultiJson.dump('foo', :pretty => true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with :indent option' do
|
19
|
+
it 'passes it on dump' do
|
20
|
+
::JSON.should_receive(:generate).with(['foo'], {:indent => "\t"}).and_return('["foo"]')
|
21
|
+
MultiJson.dump('foo', :indent => "\t")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.load' do
|
27
|
+
describe 'with :quirks_mode option' do
|
28
|
+
it 'passes it on load' do
|
29
|
+
::JSON.should_receive(:parse).with('["foo"]', {:quirks_mode => true, :create_additions => false}).and_return(['foo'])
|
30
|
+
MultiJson.load('"foo"', :quirks_mode => true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/multi_json_spec.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'adapter_shared_example'
|
3
|
+
require 'json_common_shared_example'
|
3
4
|
require 'stringio'
|
4
5
|
|
5
6
|
describe 'MultiJson' do
|
6
7
|
context 'adapters' do
|
7
|
-
before
|
8
|
-
|
9
|
-
end
|
8
|
+
before{ MultiJson.use nil }
|
9
|
+
|
10
10
|
context 'when no other json implementations are available' do
|
11
11
|
before do
|
12
12
|
@old_map = MultiJson::REQUIREMENT_MAP
|
13
13
|
@old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
|
14
14
|
@old_oj = Object.const_get :Oj if Object.const_defined?(:Oj)
|
15
15
|
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
|
16
|
+
@old_gson = Object.const_get :Gson if Object.const_defined?(:Gson)
|
16
17
|
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
|
17
18
|
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
|
18
19
|
end
|
19
20
|
Object.send :remove_const, :JSON if @old_json
|
20
21
|
Object.send :remove_const, :Oj if @old_oj
|
21
22
|
Object.send :remove_const, :Yajl if @old_yajl
|
23
|
+
Object.send :remove_const, :Gson if @old_gson
|
22
24
|
end
|
23
25
|
|
24
26
|
after do
|
@@ -28,9 +30,11 @@ describe 'MultiJson' do
|
|
28
30
|
Object.const_set :JSON, @old_json if @old_json
|
29
31
|
Object.const_set :Oj, @old_oj if @old_oj
|
30
32
|
Object.const_set :Yajl, @old_yajl if @old_yajl
|
33
|
+
Object.const_set :Gson, @old_gson if @old_gson
|
31
34
|
end
|
32
35
|
|
33
36
|
it 'defaults to ok_json if no other json implementions are available' do
|
37
|
+
Kernel.stub(:warn)
|
34
38
|
expect(MultiJson.default_adapter).to eq :ok_json
|
35
39
|
end
|
36
40
|
|
@@ -52,6 +56,12 @@ describe 'MultiJson' do
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
it 'looks for adapter even if @adapter variable is nil' do
|
60
|
+
MultiJson.send(:instance_variable_set, :@adapter, nil)
|
61
|
+
MultiJson.should_receive(:default_adapter).and_return(:ok_json)
|
62
|
+
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::OkJson'
|
63
|
+
end
|
64
|
+
|
55
65
|
it 'is settable via a symbol' do
|
56
66
|
MultiJson.use :json_gem
|
57
67
|
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonGem'
|
@@ -62,18 +72,23 @@ describe 'MultiJson' do
|
|
62
72
|
expect(MultiJson.adapter.name).to eq 'MockDecoder'
|
63
73
|
end
|
64
74
|
|
65
|
-
|
66
|
-
|
75
|
+
it 'is settable via a module' do
|
76
|
+
MultiJson.use MockModuleDecoder
|
77
|
+
expect(MultiJson.adapter.name).to eq 'MockModuleDecoder'
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'using one-shot parser' do
|
81
|
+
before do
|
67
82
|
require 'multi_json/adapters/json_pure'
|
68
83
|
MultiJson::Adapters::JsonPure.should_receive(:dump).exactly(1).times.and_return('dump_something')
|
69
84
|
MultiJson::Adapters::JsonPure.should_receive(:load).exactly(1).times.and_return('load_something')
|
70
85
|
end
|
71
86
|
|
72
|
-
it
|
87
|
+
it 'should use the defined parser just for the call' do
|
73
88
|
MultiJson.use :json_gem
|
74
89
|
expect(MultiJson.dump('', :adapter => :json_pure)).to eq 'dump_something'
|
75
90
|
expect(MultiJson.load('', :adapter => :json_pure)).to eq 'load_something'
|
76
|
-
expect(MultiJson.adapter.name).to eq
|
91
|
+
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonGem'
|
77
92
|
end
|
78
93
|
end
|
79
94
|
end
|
@@ -81,38 +96,56 @@ describe 'MultiJson' do
|
|
81
96
|
it 'can set adapter for a block' do
|
82
97
|
MultiJson.use :ok_json
|
83
98
|
MultiJson.with_adapter(:json_pure) do
|
99
|
+
MultiJson.with_engine(:json_gem) do
|
100
|
+
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonGem'
|
101
|
+
end
|
84
102
|
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonPure'
|
85
103
|
end
|
86
|
-
MultiJson.with_engine(:yajl) do
|
87
|
-
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::Yajl'
|
88
|
-
end
|
89
104
|
expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::OkJson'
|
90
105
|
end
|
91
106
|
|
92
|
-
it 'does not create symbols on parse' do
|
107
|
+
it 'JSON gem does not create symbols on parse' do
|
93
108
|
MultiJson.with_engine(:json_gem) do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
110
|
+
|
111
|
+
expect{
|
112
|
+
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
113
|
+
}.to_not change{Symbol.all_symbols.count}
|
98
114
|
end
|
99
115
|
end
|
100
116
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
117
|
+
unless jruby?
|
118
|
+
it 'Oj does not create symbols on parse' do
|
119
|
+
MultiJson.with_engine(:oj) do
|
120
|
+
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
121
|
+
|
122
|
+
expect{
|
123
|
+
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
124
|
+
}.to_not change{Symbol.all_symbols.count}
|
125
|
+
end
|
107
126
|
end
|
108
127
|
end
|
109
128
|
|
110
|
-
|
111
|
-
|
129
|
+
it 'has default_options setter' do
|
130
|
+
MultiJson.use MockDecoder
|
131
|
+
MockDecoder.should_receive(:dump).with('123', :foo => 'lol', :bar => 'bar', :fizz => 'buzz')
|
132
|
+
MultiJson.default_options = { :foo => 'foo', :bar => 'bar' }
|
133
|
+
MultiJson.dump('123', :fizz => 'buzz', :foo => 'lol')
|
134
|
+
MultiJson.default_options = {}
|
135
|
+
end
|
136
|
+
|
137
|
+
%w(gson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
|
138
|
+
next if adapter == 'gson' && !jruby?
|
139
|
+
next if adapter == 'nsjsonserialization' && !macruby?
|
112
140
|
next if jruby? && (adapter == 'oj' || adapter == 'yajl')
|
141
|
+
context adapter do
|
142
|
+
it_behaves_like 'an adapter', adapter
|
143
|
+
end
|
144
|
+
end
|
113
145
|
|
146
|
+
%w(json_gem json_pure).each do |adapter|
|
114
147
|
context adapter do
|
115
|
-
it_behaves_like
|
148
|
+
it_behaves_like 'JSON-like adapter', adapter
|
116
149
|
end
|
117
150
|
end
|
118
151
|
end
|
metadata
CHANGED
@@ -1,82 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Bleigh
|
9
9
|
- Josh Kalderimis
|
10
10
|
- Erik Michaels-Ober
|
11
|
+
- Pavel Pravosud
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
|
-
cert_chain:
|
14
|
-
|
14
|
+
cert_chain:
|
15
|
+
- !binary |-
|
16
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhhZ0F3SUJB
|
17
|
+
Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREE5TVE4d0RRWURWUVFE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
+
WUpLb1pJaHZjTkFRRUZCUUFEZ2dFQkFISFNNcy9NUDBzT2FMa0V2NEpvCnp2
|
34
|
+
a20zcW41QTZ0MHZhSHg3NzRjbWVqeU1VKzV3eVN4UmV6c3BMN1VMaDlOZXVL
|
35
|
+
Mk9oVStPZTNUcHFyQWc1VEsKUjhHUUlMblZ1MkZlbUdBNnNBa1BEbGNQdGdB
|
36
|
+
NmllSTE5UFpPRjZIVkxtYy9JRC9kUC9OZ1pXV3pFZXFRS21jSwoyK0hNK1NF
|
37
|
+
RURoWmtTY1lla3c0Wk9lMTY0WnRaRzgxNm9BdjV4MHBHaXRTSWt1bVVwN1Y4
|
38
|
+
aUVaLzZlaHI3WTllClhPZzRlZXVuNUwvSmptakFSb1cya05kdmtSRDNjMkVl
|
39
|
+
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
|
40
|
+
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
|
41
|
+
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
42
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
15
43
|
dependencies:
|
16
44
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
45
|
+
name: bundler
|
18
46
|
requirement: !ruby/object:Gem::Requirement
|
19
47
|
none: false
|
20
48
|
requirements:
|
21
|
-
- -
|
49
|
+
- - ~>
|
22
50
|
- !ruby/object:Gem::Version
|
23
|
-
version: '0
|
51
|
+
version: '1.0'
|
24
52
|
type: :development
|
25
53
|
prerelease: false
|
26
54
|
version_requirements: !ruby/object:Gem::Requirement
|
27
55
|
none: false
|
28
56
|
requirements:
|
29
|
-
- -
|
57
|
+
- - ~>
|
30
58
|
- !ruby/object:Gem::Version
|
31
|
-
version: '0
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: rdoc
|
34
|
-
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
|
-
requirements:
|
37
|
-
- - ! '>='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3.9'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
|
-
requirements:
|
45
|
-
- - ! '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3.9'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
|
-
requirements:
|
53
|
-
- - ! '>='
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '2.6'
|
56
|
-
type: :development
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
|
-
requirements:
|
61
|
-
- - ! '>='
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '2.6'
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: simplecov
|
66
|
-
requirement: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
|
-
requirements:
|
69
|
-
- - ! '>='
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '0.4'
|
72
|
-
type: :development
|
73
|
-
prerelease: false
|
74
|
-
version_requirements: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
|
-
requirements:
|
77
|
-
- - ! '>='
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: '0.4'
|
59
|
+
version: '1.0'
|
80
60
|
description: A gem to provide easy switching between different JSON backends, including
|
81
61
|
Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.
|
82
62
|
email:
|
@@ -85,10 +65,11 @@ email:
|
|
85
65
|
- sferik@gmail.com
|
86
66
|
executables: []
|
87
67
|
extensions: []
|
88
|
-
extra_rdoc_files:
|
89
|
-
- LICENSE.md
|
90
|
-
- README.md
|
68
|
+
extra_rdoc_files: []
|
91
69
|
files:
|
70
|
+
- .yardopts
|
71
|
+
- CHANGELOG.md
|
72
|
+
- CONTRIBUTING.md
|
92
73
|
- LICENSE.md
|
93
74
|
- README.md
|
94
75
|
- Rakefile
|
@@ -99,7 +80,9 @@ files:
|
|
99
80
|
- .travis.yml
|
100
81
|
- spec/adapter_shared_example.rb
|
101
82
|
- spec/helper.rb
|
83
|
+
- spec/json_common_shared_example.rb
|
102
84
|
- spec/multi_json_spec.rb
|
85
|
+
- lib/multi_json/adapters/gson.rb
|
103
86
|
- lib/multi_json/adapters/json_common.rb
|
104
87
|
- lib/multi_json/adapters/json_gem.rb
|
105
88
|
- lib/multi_json/adapters/json_pure.rb
|
@@ -114,8 +97,7 @@ homepage: http://github.com/intridea/multi_json
|
|
114
97
|
licenses:
|
115
98
|
- MIT
|
116
99
|
post_install_message:
|
117
|
-
rdoc_options:
|
118
|
-
- --charset=UTF-8
|
100
|
+
rdoc_options: []
|
119
101
|
require_paths:
|
120
102
|
- lib
|
121
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -139,5 +121,6 @@ summary: A gem to provide swappable JSON backends.
|
|
139
121
|
test_files:
|
140
122
|
- spec/adapter_shared_example.rb
|
141
123
|
- spec/helper.rb
|
124
|
+
- spec/json_common_shared_example.rb
|
142
125
|
- spec/multi_json_spec.rb
|
143
126
|
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|