multi_json-maglev- 1.3.6

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.
@@ -0,0 +1,3 @@
1
+ module MultiJson
2
+ VERSION = "1.3.6" unless defined?(MultiJson::VERSION)
3
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../lib/multi_json/version", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_development_dependency 'rake', '~> 0.9'
6
+ gem.add_development_dependency 'rdoc', '~> 3.9'
7
+ gem.add_development_dependency 'rspec', '~> 2.6'
8
+ gem.add_development_dependency 'simplecov', '~> 0.4'
9
+ gem.authors = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober"]
10
+ gem.description = %q{A gem to provide easy switching between different JSON backends, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.}
11
+ gem.email = ['michael@intridea.com', 'josh.kalderimis@gmail.com', 'sferik@gmail.com']
12
+ gem.extra_rdoc_files = ['LICENSE.md', 'README.md']
13
+ gem.files = Dir['LICENSE.md', 'README.md', 'Rakefile', 'multi_json.gemspec', 'Gemfile', '.document', '.rspec', '.travis.yml' ,'spec/**/*', 'lib/**/*']
14
+ gem.homepage = 'http://github.com/intridea/multi_json'
15
+ gem.name = 'multi_json-maglev-'
16
+ gem.rdoc_options = ["--charset=UTF-8"]
17
+ gem.require_paths = ['lib']
18
+ gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.6")
19
+ gem.summary = %q{A gem to provide swappable JSON backends.}
20
+ gem.test_files = Dir['spec/**/*']
21
+ gem.version = MultiJson::VERSION
22
+ end
@@ -0,0 +1,115 @@
1
+ shared_examples_for "an adapter" do |adapter|
2
+
3
+ before do
4
+ begin
5
+ MultiJson.use adapter
6
+ rescue LoadError
7
+ pending "Adapter #{adapter} couldn't be loaded (not installed?)"
8
+ end
9
+ end
10
+
11
+ describe '.dump' do
12
+ it 'writes decodable JSON' do
13
+ [
14
+ {'abc' => 'def'},
15
+ [1, 2, 3, "4"],
16
+ ].each do |example|
17
+ MultiJson.load(MultiJson.dump(example)).should == example
18
+ end
19
+ end
20
+
21
+ it 'dumps symbol keys as strings' do
22
+ [
23
+ [
24
+ {:foo => {:bar => 'baz'}},
25
+ {'foo' => {'bar' => 'baz'}},
26
+ ],
27
+ [
28
+ [{:foo => {:bar => 'baz'}}],
29
+ [{'foo' => {'bar' => 'baz'}}],
30
+ ],
31
+ [
32
+ {:foo => [{:bar => 'baz'}]},
33
+ {'foo' => [{'bar' => 'baz'}]},
34
+ ]
35
+ ].each do |example, expected|
36
+ dumped_json = MultiJson.dump(example)
37
+ MultiJson.load(dumped_json).should == expected
38
+ end
39
+ end
40
+
41
+ it 'dumps rootless JSON' do
42
+ MultiJson.dump("random rootless string").should == "\"random rootless string\""
43
+ MultiJson.dump(123).should == "123"
44
+ end
45
+
46
+ it 'passes options to the adapter' do
47
+ MultiJson.adapter.should_receive(:dump).with('foo', {:bar => :baz})
48
+ MultiJson.dump('foo', :bar => :baz)
49
+ end
50
+
51
+ if adapter == 'json_gem' || adapter == 'json_pure'
52
+ describe 'with :pretty option set to true' do
53
+ it 'passes default pretty options' do
54
+ object = 'foo'
55
+ object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
56
+ MultiJson.dump(object,:pretty => true)
57
+ end
58
+ end
59
+ end
60
+
61
+ it 'dumps custom objects which implement as_json' do
62
+ MultiJson.dump(TimeWithZone.new).should == "\"2005-02-01T15:15:10Z\""
63
+ end
64
+ end
65
+
66
+ describe '.load' do
67
+ it 'properly loads valid JSON' do
68
+ MultiJson.load('{"abc":"def"}').should == {'abc' => 'def'}
69
+ end
70
+
71
+ it 'raises MultiJson::DecodeError on invalid JSON' do
72
+ lambda do
73
+ MultiJson.load('{"abc"}')
74
+ end.should raise_error(MultiJson::DecodeError)
75
+ end
76
+
77
+ it 'raises MultiJson::DecodeError with data on invalid JSON' do
78
+ data = '{invalid}'
79
+ begin
80
+ MultiJson.load(data)
81
+ rescue MultiJson::DecodeError => de
82
+ de.data.should == data
83
+ end
84
+ end
85
+
86
+ it 'stringifys symbol keys when encoding' do
87
+ dumped_json = MultiJson.dump(:a => 1, :b => {:c => 2})
88
+ MultiJson.load(dumped_json).should == {"a" => 1, "b" => {"c" => 2}}
89
+ end
90
+
91
+ it 'properly loads valid JSON in StringIOs' do
92
+ json = StringIO.new('{"abc":"def"}')
93
+ MultiJson.load(json).should == {'abc' => 'def'}
94
+ end
95
+
96
+ it 'allows for symbolization of keys' do
97
+ [
98
+ [
99
+ '{"abc":{"def":"hgi"}}',
100
+ {:abc => {:def => 'hgi'}},
101
+ ],
102
+ [
103
+ '[{"abc":{"def":"hgi"}}]',
104
+ [{:abc => {:def => 'hgi'}}],
105
+ ],
106
+ [
107
+ '{"abc":[{"def":"hgi"}]}',
108
+ {:abc => [{:def => 'hgi'}]},
109
+ ],
110
+ ].each do |example, expected|
111
+ MultiJson.load(example, :symbolize_keys => true).should == expected
112
+ end
113
+ end
114
+ end
115
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,32 @@
1
+ def jruby?
2
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
3
+ end
4
+
5
+ def macruby?
6
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
7
+ end
8
+
9
+ unless ENV['CI'] || macruby?
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ add_filter 'spec'
13
+ end
14
+ end
15
+ require 'multi_json'
16
+ require 'rspec'
17
+
18
+ class MockDecoder
19
+ def self.load(string, options={})
20
+ {'abc' => 'def'}
21
+ end
22
+
23
+ def self.dump(string)
24
+ '{"abc":"def"}'
25
+ end
26
+ end
27
+
28
+ class TimeWithZone
29
+ def to_json(options={})
30
+ "\"2005-02-01T15:15:10Z\""
31
+ end
32
+ end
@@ -0,0 +1,87 @@
1
+ require 'helper'
2
+ require 'adapter_shared_example'
3
+ require 'stringio'
4
+
5
+ describe 'MultiJson' do
6
+ context 'adapters' do
7
+ before do
8
+ MultiJson.use nil
9
+ end
10
+ context 'when no other json implementations are available' do
11
+ before do
12
+ @old_map = MultiJson::REQUIREMENT_MAP
13
+ @old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
14
+ @old_oj = Object.const_get :Oj if Object.const_defined?(:Oj)
15
+ @old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
16
+ MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
17
+ MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
18
+ end
19
+ Object.send :remove_const, :JSON if @old_json
20
+ Object.send :remove_const, :Oj if @old_oj
21
+ Object.send :remove_const, :Yajl if @old_yajl
22
+ end
23
+
24
+ after do
25
+ @old_map.each_with_index do |(library, adapter), index|
26
+ MultiJson::REQUIREMENT_MAP[index] = [library, adapter]
27
+ end
28
+ Object.const_set :JSON, @old_json if @old_json
29
+ Object.const_set :Oj, @old_oj if @old_oj
30
+ Object.const_set :Yajl, @old_yajl if @old_yajl
31
+ end
32
+
33
+ it 'defaults to ok_json if no other json implementions are available' do
34
+ MultiJson.default_adapter.should == :ok_json
35
+ end
36
+
37
+ it 'prints a warning' do
38
+ Kernel.should_receive(:warn).with(/warning/i)
39
+ MultiJson.default_adapter
40
+ end
41
+ end
42
+
43
+ it 'defaults to the best available gem' do
44
+ unless jruby?
45
+ require 'oj'
46
+ MultiJson.adapter.name.should == 'MultiJson::Adapters::Oj'
47
+ else
48
+ require 'json'
49
+ MultiJson.adapter.name.should == 'MultiJson::Adapters::JsonGem'
50
+ end
51
+ end
52
+
53
+ it 'is settable via a symbol' do
54
+ MultiJson.use :json_gem
55
+ MultiJson.adapter.name.should == 'MultiJson::Adapters::JsonGem'
56
+ end
57
+
58
+ it 'is settable via a class' do
59
+ MultiJson.use MockDecoder
60
+ MultiJson.adapter.name.should == 'MockDecoder'
61
+ end
62
+
63
+ context "using one-shot parser" do
64
+ before(:each) do
65
+ require 'multi_json/adapters/json_pure'
66
+ MultiJson::Adapters::JsonPure.should_receive(:dump).exactly(1).times.and_return('dump_something')
67
+ MultiJson::Adapters::JsonPure.should_receive(:load).exactly(1).times.and_return('load_something')
68
+ end
69
+
70
+ it "should use the defined parser just for the call" do
71
+ MultiJson.use :json_gem
72
+ MultiJson.dump('', :adapter => :json_pure).should eql('dump_something')
73
+ MultiJson.load('', :adapter => :json_pure).should eql('load_something')
74
+ MultiJson.adapter.to_s.should eql("MultiJson::Adapters::JsonGem")
75
+ end
76
+ end
77
+ end
78
+
79
+ %w(json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
80
+ next if !macruby? && adapter == 'nsjsonserialization'
81
+ next if jruby? && (adapter == 'oj' || adapter == 'yajl')
82
+
83
+ context adapter do
84
+ it_should_behave_like "an adapter", adapter
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_json-maglev-
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Bleigh
9
+ - Josh Kalderimis
10
+ - Erik Michaels-Ober
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-09-01 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ requirement: &70149056871900 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '0.9'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *70149056871900
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: &70149056870920 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '3.9'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *70149056870920
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &70149056870440 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.6'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70149056870440
49
+ - !ruby/object:Gem::Dependency
50
+ name: simplecov
51
+ requirement: &70149056969960 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '0.4'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70149056969960
60
+ description: A gem to provide easy switching between different JSON backends, including
61
+ Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.
62
+ email:
63
+ - michael@intridea.com
64
+ - josh.kalderimis@gmail.com
65
+ - sferik@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files:
69
+ - LICENSE.md
70
+ - README.md
71
+ files:
72
+ - LICENSE.md
73
+ - README.md
74
+ - Rakefile
75
+ - multi_json.gemspec
76
+ - Gemfile
77
+ - .document
78
+ - .rspec
79
+ - .travis.yml
80
+ - spec/adapter_shared_example.rb
81
+ - spec/multi_json_spec.rb
82
+ - spec/helper.rb
83
+ - lib/multi_json.rb
84
+ - lib/multi_json/adapters/json_common.rb
85
+ - lib/multi_json/adapters/json_gem.rb
86
+ - lib/multi_json/adapters/json_pure.rb
87
+ - lib/multi_json/adapters/nsjsonserialization.rb
88
+ - lib/multi_json/adapters/oj.rb
89
+ - lib/multi_json/adapters/ok_json.rb
90
+ - lib/multi_json/adapters/yajl.rb
91
+ - lib/multi_json/vendor/okjson.rb
92
+ - lib/multi_json/version.rb
93
+ homepage: http://github.com/intridea/multi_json
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.6
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.11
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: A gem to provide swappable JSON backends.
118
+ test_files:
119
+ - spec/adapter_shared_example.rb
120
+ - spec/multi_json_spec.rb
121
+ - spec/helper.rb