multi_json 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -3
- data/Gemfile +1 -2
- data/README.md +47 -23
- data/Rakefile +9 -7
- data/lib/multi_json.rb +15 -4
- data/lib/multi_json/engines/json_common.rb +27 -0
- data/lib/multi_json/engines/json_gem.rb +2 -11
- data/lib/multi_json/engines/json_pure.rb +2 -11
- data/lib/multi_json/engines/ok_json.rb +5 -5
- data/lib/multi_json/engines/yajl.rb +2 -2
- data/lib/multi_json/vendor/ok_json.rb +435 -429
- data/lib/multi_json/version.rb +1 -1
- data/multi_json.gemspec +4 -5
- data/spec/helper.rb +30 -6
- data/spec/multi_json_spec.rb +62 -18
- metadata +63 -67
- data/.gemtest +0 -0
- data/.gitignore +0 -34
data/lib/multi_json/version.rb
CHANGED
data/multi_json.gemspec
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
require File.expand_path("../lib/multi_json/version", __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.add_development_dependency 'rake', '~> 0.9'
|
6
|
-
gem.add_development_dependency 'rdoc', '3.
|
6
|
+
gem.add_development_dependency 'rdoc', '~> 3.9'
|
7
7
|
gem.add_development_dependency 'rspec', '~> 2.6'
|
8
8
|
gem.add_development_dependency 'simplecov', '~> 0.4'
|
9
9
|
gem.authors = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober"]
|
10
10
|
gem.description = %q{A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON gem, JSON pure, or a vendored version of okjson.}
|
11
11
|
gem.email = ['michael@intridea.com', 'josh.kalderimis@gmail.com', 'sferik@gmail.com']
|
12
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
13
12
|
gem.extra_rdoc_files = ['LICENSE.md', 'README.md']
|
14
|
-
gem.files =
|
13
|
+
gem.files = Dir['LICENSE.md', 'README.md', 'Rakefile', 'multi_json.gemspec', 'Gemfile', '.document', '.rspec', '.travis.yml' ,'spec/**/*', 'lib/**/*']
|
15
14
|
gem.homepage = 'http://github.com/intridea/multi_json'
|
16
15
|
gem.name = 'multi_json'
|
17
16
|
gem.rdoc_options = ["--charset=UTF-8"]
|
18
17
|
gem.require_paths = ['lib']
|
19
18
|
gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.6")
|
20
19
|
gem.summary = %q{A gem to provide swappable JSON backends.}
|
21
|
-
gem.test_files =
|
20
|
+
gem.test_files = Dir['spec/**/*']
|
22
21
|
gem.version = MultiJson::VERSION
|
23
22
|
end
|
data/spec/helper.rb
CHANGED
@@ -1,11 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Bundler.setup
|
4
|
-
rescue LoadError
|
5
|
-
warn "[WARNING]: It is recommended that you use bundler during development: gem install bundler"
|
1
|
+
['..', '../../lib'].each do |path|
|
2
|
+
$:.unshift dir if dir = File.expand_path(path, __FILE__) and not $:.include?(dir)
|
6
3
|
end
|
7
4
|
|
8
5
|
require 'simplecov'
|
9
6
|
SimpleCov.start
|
10
|
-
|
7
|
+
|
11
8
|
require 'multi_json'
|
9
|
+
require 'rspec'
|
10
|
+
|
11
|
+
|
12
|
+
class MockDecoder
|
13
|
+
def self.decode(string, options = {})
|
14
|
+
{'abc' => 'def'}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encode(string)
|
18
|
+
'{"abc":"def"}'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TimeWithZone
|
23
|
+
def to_json(options = {})
|
24
|
+
"\"2005-02-01T15:15:10Z\""
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def yajl_on_travis(engine)
|
30
|
+
ENV['TRAVIS'] && engine == 'yajl' && jruby?
|
31
|
+
end
|
32
|
+
|
33
|
+
def jruby?
|
34
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
35
|
+
end
|
data/spec/multi_json_spec.rb
CHANGED
@@ -1,35 +1,46 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'stringio'
|
3
3
|
|
4
|
-
class MockDecoder
|
5
|
-
def self.decode(string, options = {})
|
6
|
-
{'abc' => 'def'}
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.encode(string)
|
10
|
-
'{"abc":"def"}'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
describe "MultiJson" do
|
15
5
|
context 'engines' do
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
context 'when no other json implementations are available' do
|
7
|
+
before(:each) do
|
8
|
+
@old_map = MultiJson::REQUIREMENT_MAP
|
9
|
+
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
|
10
|
+
@old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
|
19
11
|
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, engine), index|
|
20
12
|
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", engine]
|
21
13
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
Object.send :remove_const, :Yajl if @old_yajl
|
15
|
+
Object.send :remove_const, :JSON if @old_json
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
@old_map.each_with_index do |(library, engine), index|
|
25
20
|
MultiJson::REQUIREMENT_MAP[index] = [library, engine]
|
26
21
|
end
|
22
|
+
Object.const_set :Yajl, @old_yajl if @old_yajl
|
23
|
+
Object.const_set :JSON, @old_json if @old_json
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'defaults to ok_json if no other json implementions are available' do
|
27
|
+
MultiJson.default_engine.should == :ok_json
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'prints a warning' do
|
31
|
+
Kernel.should_receive(:warn).with(/warning/i)
|
32
|
+
MultiJson.default_engine
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
it 'defaults to the best available gem' do
|
31
|
-
|
32
|
-
|
37
|
+
unless jruby?
|
38
|
+
require 'yajl'
|
39
|
+
MultiJson.engine.name.should == 'MultiJson::Engines::Yajl'
|
40
|
+
else
|
41
|
+
require 'json'
|
42
|
+
MultiJson.engine.name.should == 'MultiJson::Engines::JsonGem'
|
43
|
+
end
|
33
44
|
end
|
34
45
|
|
35
46
|
it 'is settable via a symbol' do
|
@@ -44,6 +55,11 @@ describe "MultiJson" do
|
|
44
55
|
end
|
45
56
|
|
46
57
|
%w(json_gem json_pure ok_json yajl).each do |engine|
|
58
|
+
if yajl_on_travis(engine)
|
59
|
+
puts "Yajl with JRuby is not tested on Travis as C-exts are turned off due to there experimental nature"
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
47
63
|
context engine do
|
48
64
|
before do
|
49
65
|
begin
|
@@ -87,6 +103,25 @@ describe "MultiJson" do
|
|
87
103
|
MultiJson.encode("random rootless string").should == "\"random rootless string\""
|
88
104
|
MultiJson.encode(123).should == "123"
|
89
105
|
end
|
106
|
+
|
107
|
+
it 'passes options to the engine' do
|
108
|
+
MultiJson.engine.should_receive(:encode).with('foo', {:bar => :baz})
|
109
|
+
MultiJson.encode('foo', :bar => :baz)
|
110
|
+
end
|
111
|
+
|
112
|
+
if engine == 'json_gem' || engine == 'json_pure'
|
113
|
+
describe 'with :pretty option set to true' do
|
114
|
+
it 'passes default pretty options' do
|
115
|
+
object = 'foo'
|
116
|
+
object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
|
117
|
+
MultiJson.encode(object,:pretty => true)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "encodes custom objects which implement as_json" do
|
123
|
+
MultiJson.encode(TimeWithZone.new).should == "\"2005-02-01T15:15:10Z\""
|
124
|
+
end
|
90
125
|
end
|
91
126
|
|
92
127
|
describe '.decode' do
|
@@ -100,6 +135,15 @@ describe "MultiJson" do
|
|
100
135
|
end.should raise_error(MultiJson::DecodeError)
|
101
136
|
end
|
102
137
|
|
138
|
+
it 'raises MultiJson::DecodeError with data on invalid JSON' do
|
139
|
+
data = '{invalid}'
|
140
|
+
begin
|
141
|
+
MultiJson.decode(data)
|
142
|
+
rescue MultiJson::DecodeError => de
|
143
|
+
de.data.should == data
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
103
147
|
it 'stringifys symbol keys when encoding' do
|
104
148
|
encoded_json = MultiJson.encode(:a => 1, :b => {:c => 2})
|
105
149
|
MultiJson.decode(encoded_json).should == { "a" => 1, "b" => { "c" => 2 } }
|
metadata
CHANGED
@@ -1,122 +1,118 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_json
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Michael Bleigh
|
9
9
|
- Josh Kalderimis
|
10
10
|
- Erik Michaels-Ober
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2011-11-28 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
18
17
|
name: rake
|
19
|
-
|
20
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &70345404971980 !ruby/object:Gem::Requirement
|
21
19
|
none: false
|
22
|
-
requirements:
|
20
|
+
requirements:
|
23
21
|
- - ~>
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version:
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0.9'
|
26
24
|
type: :development
|
27
|
-
version_requirements: *id001
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rdoc
|
30
25
|
prerelease: false
|
31
|
-
|
26
|
+
version_requirements: *70345404971980
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: &70345404970940 !ruby/object:Gem::Requirement
|
32
30
|
none: false
|
33
|
-
requirements:
|
34
|
-
- -
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 3.
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.9'
|
37
35
|
type: :development
|
38
|
-
version_requirements: *id002
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
36
|
prerelease: false
|
42
|
-
|
37
|
+
version_requirements: *70345404970940
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &70345404968560 !ruby/object:Gem::Requirement
|
43
41
|
none: false
|
44
|
-
requirements:
|
42
|
+
requirements:
|
45
43
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version:
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.6'
|
48
46
|
type: :development
|
49
|
-
version_requirements: *id003
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: simplecov
|
52
47
|
prerelease: false
|
53
|
-
|
48
|
+
version_requirements: *70345404968560
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: simplecov
|
51
|
+
requirement: &70345404967560 !ruby/object:Gem::Requirement
|
54
52
|
none: false
|
55
|
-
requirements:
|
53
|
+
requirements:
|
56
54
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version:
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.4'
|
59
57
|
type: :development
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *70345404967560
|
60
|
+
description: A gem to provide swappable JSON backends utilizing Yajl::Ruby, the JSON
|
61
|
+
gem, JSON pure, or a vendored version of okjson.
|
62
|
+
email:
|
63
63
|
- michael@intridea.com
|
64
64
|
- josh.kalderimis@gmail.com
|
65
65
|
- sferik@gmail.com
|
66
66
|
executables: []
|
67
|
-
|
68
67
|
extensions: []
|
69
|
-
|
70
|
-
extra_rdoc_files:
|
68
|
+
extra_rdoc_files:
|
71
69
|
- LICENSE.md
|
72
70
|
- README.md
|
73
|
-
files:
|
74
|
-
- .document
|
75
|
-
- .gemtest
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .travis.yml
|
79
|
-
- Gemfile
|
71
|
+
files:
|
80
72
|
- LICENSE.md
|
81
73
|
- README.md
|
82
74
|
- Rakefile
|
83
|
-
-
|
75
|
+
- multi_json.gemspec
|
76
|
+
- Gemfile
|
77
|
+
- .document
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
|
+
- spec/helper.rb
|
81
|
+
- spec/multi_json_spec.rb
|
82
|
+
- lib/multi_json/engines/json_common.rb
|
84
83
|
- lib/multi_json/engines/json_gem.rb
|
85
84
|
- lib/multi_json/engines/json_pure.rb
|
86
85
|
- lib/multi_json/engines/ok_json.rb
|
87
86
|
- lib/multi_json/engines/yajl.rb
|
88
87
|
- lib/multi_json/vendor/ok_json.rb
|
89
88
|
- lib/multi_json/version.rb
|
90
|
-
- multi_json.
|
91
|
-
- spec/helper.rb
|
92
|
-
- spec/multi_json_spec.rb
|
89
|
+
- lib/multi_json.rb
|
93
90
|
homepage: http://github.com/intridea/multi_json
|
94
91
|
licenses: []
|
95
|
-
|
96
92
|
post_install_message:
|
97
|
-
rdoc_options:
|
93
|
+
rdoc_options:
|
98
94
|
- --charset=UTF-8
|
99
|
-
require_paths:
|
95
|
+
require_paths:
|
100
96
|
- lib
|
101
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
98
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version:
|
107
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
104
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
112
108
|
version: 1.3.6
|
113
109
|
requirements: []
|
114
|
-
|
115
110
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.11
|
117
112
|
signing_key:
|
118
113
|
specification_version: 3
|
119
114
|
summary: A gem to provide swappable JSON backends.
|
120
|
-
test_files:
|
115
|
+
test_files:
|
121
116
|
- spec/helper.rb
|
122
117
|
- spec/multi_json_spec.rb
|
118
|
+
has_rdoc:
|
data/.gemtest
DELETED
File without changes
|
data/.gitignore
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## PROJECT::GENERAL
|
17
|
-
coverage
|
18
|
-
doc
|
19
|
-
rdoc
|
20
|
-
log
|
21
|
-
|
22
|
-
## BUNDLER
|
23
|
-
*.gem
|
24
|
-
.bundle
|
25
|
-
pkg
|
26
|
-
Gemfile.lock
|
27
|
-
|
28
|
-
## RCOV
|
29
|
-
coverage.data
|
30
|
-
|
31
|
-
## RUBINIUS
|
32
|
-
*.rbc
|
33
|
-
|
34
|
-
## PROJECT::SPECIFIC
|