multi_json 1.5.0 → 1.12.1

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.
data/lib/multi_json.rb CHANGED
@@ -1,130 +1,161 @@
1
+ require 'multi_json/options'
2
+ require 'multi_json/version'
3
+ require 'multi_json/adapter_error'
4
+ require 'multi_json/parse_error'
5
+ require 'multi_json/options_cache'
6
+
1
7
  module MultiJson
2
- class DecodeError < StandardError
3
- attr_reader :data
4
- def initialize(message="", backtrace=[], data="")
5
- super(message)
6
- self.set_backtrace(backtrace)
7
- @data = data
8
+ include Options
9
+ extend self
10
+
11
+ def default_options=(value)
12
+ Kernel.warn "MultiJson.default_options setter is deprecated\n" \
13
+ 'Use MultiJson.load_options and MultiJson.dump_options instead'
14
+
15
+ self.load_options = self.dump_options = value
16
+ end
17
+
18
+ def default_options
19
+ Kernel.warn "MultiJson.default_options is deprecated\n" \
20
+ 'Use MultiJson.load_options or MultiJson.dump_options instead'
21
+
22
+ load_options
23
+ end
24
+
25
+ %w(cached_options reset_cached_options!).each do |method_name|
26
+ define_method method_name do |*|
27
+ Kernel.warn "MultiJson.#{method_name} method is deprecated and no longer used."
8
28
  end
9
29
  end
10
30
 
11
- @adapter = nil
31
+ ALIASES = {'jrjackson' => 'jr_jackson'}
12
32
 
13
33
  REQUIREMENT_MAP = [
14
- ["oj", :oj],
15
- ["yajl", :yajl],
16
- ["json", :json_gem],
17
- ["json/pure", :json_pure]
34
+ [:oj, 'oj'],
35
+ [:yajl, 'yajl'],
36
+ [:jr_jackson, 'jrjackson'],
37
+ [:json_gem, 'json/ext'],
38
+ [:gson, 'gson'],
39
+ [:json_pure, 'json/pure'],
18
40
  ]
19
41
 
20
- class << self
21
-
22
- # The default adapter based on what you currently
23
- # have loaded and installed. First checks to see
24
- # if any adapters are already loaded, then checks
25
- # to see which are installed if none are loaded.
26
- def default_adapter
27
- return :oj if defined?(::Oj)
28
- return :yajl if defined?(::Yajl)
29
- return :json_gem if defined?(::JSON)
30
-
31
- REQUIREMENT_MAP.each do |(library, adapter)|
32
- begin
33
- require library
34
- return adapter
35
- rescue LoadError
36
- next
37
- end
38
- end
42
+ # The default adapter based on what you currently
43
+ # have loaded and installed. First checks to see
44
+ # if any adapters are already loaded, then checks
45
+ # to see which are installed if none are loaded.
46
+ def default_adapter
47
+ return :oj if defined?(::Oj)
48
+ return :yajl if defined?(::Yajl)
49
+ return :jr_jackson if defined?(::JrJackson)
50
+ return :json_gem if defined?(::JSON::JSON_LOADED)
51
+ return :gson if defined?(::Gson)
39
52
 
40
- Kernel.warn "[WARNING] MultiJson is using the default adapter (ok_json). We recommend loading a different JSON library to improve performance."
41
- :ok_json
42
- end
43
- # :nodoc:
44
- alias :default_engine :default_adapter
45
-
46
- # Get the current adapter class.
47
- def adapter
48
- return @adapter if @adapter
49
- self.use self.default_adapter
50
- @adapter
51
- end
52
- # :nodoc:
53
- alias :engine :adapter
54
-
55
- # Set the JSON parser utilizing a symbol, string, or class.
56
- # Supported by default are:
57
- #
58
- # * <tt>:oj</tt>
59
- # * <tt>:json_gem</tt>
60
- # * <tt>:json_pure</tt>
61
- # * <tt>:ok_json</tt>
62
- # * <tt>:yajl</tt>
63
- # * <tt>:nsjsonserialization</tt> (MacRuby only)
64
- def use(new_adapter)
65
- @adapter = load_adapter(new_adapter)
66
- end
67
- alias :adapter= :use
68
- # :nodoc:
69
- alias :engine= :use
70
-
71
- def load_adapter(new_adapter)
72
- case new_adapter
73
- when String, Symbol
74
- require "multi_json/adapters/#{new_adapter}"
75
- MultiJson::Adapters.const_get(:"#{new_adapter.to_s.split('_').map{|s| s.capitalize}.join('')}")
76
- when NilClass, FalseClass
77
- default_adapter = self.default_adapter
78
- require "multi_json/adapters/#{default_adapter}"
79
- MultiJson::Adapters.const_get(:"#{default_adapter.to_s.split('_').map{|s| s.capitalize}.join('')}")
80
- when Class
81
- new_adapter
82
- else
83
- raise "Did not recognize your adapter specification. Please specify either a symbol or a class."
84
- end
85
- end
86
-
87
- # Decode a JSON string into Ruby.
88
- #
89
- # <b>Options</b>
90
- #
91
- # <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
92
- # <tt>:adapter</tt> :: If set, the selected engine will be used just for the call.
93
- def load(string, options={})
94
- adapter = current_adapter(options)
53
+ REQUIREMENT_MAP.each do |adapter, library|
95
54
  begin
96
- adapter.load(string, options)
97
- rescue adapter::ParseError => exception
98
- raise DecodeError.new(exception.message, exception.backtrace, string)
55
+ require library
56
+ return adapter
57
+ rescue ::LoadError
58
+ next
99
59
  end
100
60
  end
101
- # :nodoc:
102
- alias :decode :load
103
-
104
- def current_adapter(options)
105
- if new_adapter = (options || {}).delete(:adapter)
106
- load_adapter(new_adapter)
107
- else
108
- adapter
109
- end
61
+
62
+ Kernel.warn '[WARNING] MultiJson is using the default adapter (ok_json). ' \
63
+ 'We recommend loading a different JSON library to improve performance.'
64
+
65
+ :ok_json
66
+ end
67
+ alias_method :default_engine, :default_adapter
68
+
69
+ # Get the current adapter class.
70
+ def adapter
71
+ return @adapter if defined?(@adapter) && @adapter
72
+
73
+ use nil # load default adapter
74
+
75
+ @adapter
76
+ end
77
+ alias_method :engine, :adapter
78
+
79
+ # Set the JSON parser utilizing a symbol, string, or class.
80
+ # Supported by default are:
81
+ #
82
+ # * <tt>:oj</tt>
83
+ # * <tt>:json_gem</tt>
84
+ # * <tt>:json_pure</tt>
85
+ # * <tt>:ok_json</tt>
86
+ # * <tt>:yajl</tt>
87
+ # * <tt>:nsjsonserialization</tt> (MacRuby only)
88
+ # * <tt>:gson</tt> (JRuby only)
89
+ # * <tt>:jr_jackson</tt> (JRuby only)
90
+ def use(new_adapter)
91
+ @adapter = load_adapter(new_adapter)
92
+ ensure
93
+ OptionsCache.reset
94
+ end
95
+ alias_method :adapter=, :use
96
+ alias_method :engine=, :use
97
+
98
+ def load_adapter(new_adapter)
99
+ case new_adapter
100
+ when String, Symbol
101
+ load_adapter_from_string_name new_adapter.to_s
102
+ when NilClass, FalseClass
103
+ load_adapter default_adapter
104
+ when Class, Module
105
+ new_adapter
106
+ else
107
+ fail ::LoadError, new_adapter
110
108
  end
109
+ rescue ::LoadError => exception
110
+ raise AdapterError.build(exception)
111
+ end
111
112
 
112
- # Encodes a Ruby object as JSON.
113
- def dump(object, options={})
114
- adapter = current_adapter(options)
115
- adapter.dump(object, options)
113
+ # Decode a JSON string into Ruby.
114
+ #
115
+ # <b>Options</b>
116
+ #
117
+ # <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
118
+ # <tt>:adapter</tt> :: If set, the selected adapter will be used for this call.
119
+ def load(string, options = {})
120
+ adapter = current_adapter(options)
121
+ begin
122
+ adapter.load(string, options)
123
+ rescue adapter::ParseError => exception
124
+ raise ParseError.build(exception, string)
116
125
  end
117
- # :nodoc:
118
- alias :encode :dump
119
-
120
- def with_adapter(new_adapter)
121
- old_adapter, self.adapter = adapter, new_adapter
122
- yield
123
- ensure
124
- self.adapter = old_adapter
126
+ end
127
+ alias_method :decode, :load
128
+
129
+ def current_adapter(options = {})
130
+ if (new_adapter = options[:adapter])
131
+ load_adapter(new_adapter)
132
+ else
133
+ adapter
125
134
  end
126
- alias :with_engine :with_adapter
135
+ end
127
136
 
137
+ # Encodes a Ruby object as JSON.
138
+ def dump(object, options = {})
139
+ current_adapter(options).dump(object, options)
128
140
  end
141
+ alias_method :encode, :dump
129
142
 
143
+ # Executes passed block using specified adapter.
144
+ def with_adapter(new_adapter)
145
+ old_adapter = adapter
146
+ self.adapter = new_adapter
147
+ yield
148
+ ensure
149
+ self.adapter = old_adapter
150
+ end
151
+ alias_method :with_engine, :with_adapter
152
+
153
+ private
154
+
155
+ def load_adapter_from_string_name(name)
156
+ name = ALIASES.fetch(name, name)
157
+ require "multi_json/adapters/#{name.downcase}"
158
+ klass_name = name.to_s.split('_').map(&:capitalize) * ''
159
+ MultiJson::Adapters.const_get(klass_name)
160
+ end
130
161
  end
data/multi_json.gemspec CHANGED
@@ -1,23 +1,20 @@
1
- # encoding: utf-8
2
- require File.expand_path("../lib/multi_json/version", __FILE__)
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/multi_json/version.rb', __FILE__)
3
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.licenses = ['MIT']
16
- gem.name = 'multi_json'
17
- gem.rdoc_options = ["--charset=UTF-8"]
18
- gem.require_paths = ['lib']
19
- gem.required_rubygems_version = Gem::Requirement.new(">= 1.3.6")
20
- gem.summary = %q{A gem to provide swappable JSON backends.}
21
- gem.test_files = Dir['spec/**/*']
22
- gem.version = MultiJson::VERSION
4
+ Gem::Specification.new do |spec|
5
+ spec.authors = ['Michael Bleigh', 'Josh Kalderimis', 'Erik Michaels-Ober', 'Pavel Pravosud']
6
+ spec.cert_chain = %w(certs/rwz.pem)
7
+ spec.summary = 'A common interface to multiple JSON libraries.'
8
+ spec.description = 'A common interface to multiple JSON libraries, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb, JrJackson, and OkJson.'
9
+ spec.email = %w(michael@intridea.com josh.kalderimis@gmail.com sferik@gmail.com pavel@pravosud.com)
10
+ spec.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE.md', 'README.md', 'multi_json.gemspec', 'lib/**/*']
11
+ spec.homepage = 'http://github.com/intridea/multi_json'
12
+ spec.license = 'MIT'
13
+ spec.name = 'multi_json'
14
+ spec.require_path = 'lib'
15
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
16
+ spec.version = MultiJson::Version
17
+
18
+ spec.required_rubygems_version = '>= 1.3.5'
19
+ spec.add_development_dependency 'bundler', '~> 1.0'
23
20
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,105 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_json
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.0
4
+ version: 1.12.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Bleigh
9
8
  - Josh Kalderimis
10
9
  - Erik Michaels-Ober
10
+ - Pavel Pravosud
11
11
  autorequire:
12
12
  bindir: bin
13
- cert_chain: []
14
- date: 2012-12-10 00:00:00.000000000 Z
13
+ cert_chain:
14
+ - |
15
+ -----BEGIN CERTIFICATE-----
16
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVwYXZl
17
+ bDEYMBYGCgmSJomT8ixkARkWCHByYXZvc3VkMRMwEQYKCZImiZPyLGQBGRYDY29t
18
+ MB4XDTE2MDQyNDIyMDk1MVoXDTE3MDQyNDIyMDk1MVowPzEOMAwGA1UEAwwFcGF2
19
+ ZWwxGDAWBgoJkiaJk/IsZAEZFghwcmF2b3N1ZDETMBEGCgmSJomT8ixkARkWA2Nv
20
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK+YCSpSUOeZvxOyp0Zm
21
+ DhlQ9Kc8ZxgaB3ekCS6lp7hV+eE6nZ84j4RLEqhfx0Vffx+yCmSx0lWum6eY9aOy
22
+ rr+uCtiSiL+HR7t6KHqQ5myXwIvT7B+SqMYw8223fMFZMUit73PfTaMlIon+EsZB
23
+ 9TWzVU7MSRIHLr8P92/kExOuDhVcqFgmz+pWLeZjCk7r0JI0vxacFEK+ONjXThHk
24
+ W1IRwy8qaFNiUdnIfTRgZV45T/PHzuLttdkgySTDQkZp198t9Y0m0eEDhpPjHNlr
25
+ KoXtqUIqk1lmgsKKrOj4vsSX004v869GT45C4qR4/Oa2OyUsWiPf8N3GCYDBnK9C
26
+ RDcCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFKm/
27
+ jUdmc0kO/erio7IwB4zhYGmxMB0GA1UdEQQWMBSBEnBhdmVsQHByYXZvc3VkLmNv
28
+ bTAdBgNVHRIEFjAUgRJwYXZlbEBwcmF2b3N1ZC5jb20wDQYJKoZIhvcNAQEFBQAD
29
+ ggEBAGZprwh9PfxTaukluduGO2NWJpI5NC7A/OpoVFrtLTlMKDeoPvCgmNdSejS3
30
+ 6CyH8P3SI3OEkymRnLtQiJeQ//WDb7QPPQDPG0ZuxAylc35ITz7jTPAFC41AoTWM
31
+ eSDWXP6yq0Gi6vlcvyIoBrvfFRPsg/gGhUp5DYKDLYzaEjNE30bME9fwDvlab7XR
32
+ v4so5Zmmcof+9apAoaXDtj7HijhJWJcia8GWN5ycuDX38qMcpSU9/PF84s567W6e
33
+ De8xFEGqLG8vclcTv7gGjDJH5FJTXuwLg41wc8p4ONXEBgLiaC7+S/DVDXWpYxuB
34
+ akI17ua4eRKTFNvBtzP1802SP1k=
35
+ -----END CERTIFICATE-----
36
+ date: 2016-05-18 00:00:00.000000000 Z
15
37
  dependencies:
16
38
  - !ruby/object:Gem::Dependency
17
- version_requirements: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0.9'
22
- none: false
23
- name: rake
24
- type: :development
25
- prerelease: false
39
+ name: bundler
26
40
  requirement: !ruby/object:Gem::Requirement
27
41
  requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0.9'
31
- none: false
32
- - !ruby/object:Gem::Dependency
33
- version_requirements: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - ! '>='
42
+ - - "~>"
36
43
  - !ruby/object:Gem::Version
37
- version: '3.9'
38
- none: false
39
- name: rdoc
44
+ version: '1.0'
40
45
  type: :development
41
46
  prerelease: false
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '3.9'
47
- none: false
48
- - !ruby/object:Gem::Dependency
49
47
  version_requirements: !ruby/object:Gem::Requirement
50
48
  requirements:
51
- - - ! '>='
49
+ - - "~>"
52
50
  - !ruby/object:Gem::Version
53
- version: '2.6'
54
- none: false
55
- name: rspec
56
- type: :development
57
- prerelease: false
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '2.6'
63
- none: false
64
- - !ruby/object:Gem::Dependency
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0.4'
70
- none: false
71
- name: simplecov
72
- type: :development
73
- prerelease: false
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0.4'
79
- none: false
80
- description: A gem to provide easy switching between different JSON backends, including
81
- Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.
51
+ version: '1.0'
52
+ description: A common interface to multiple JSON libraries, including Oj, Yajl, the
53
+ JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb,
54
+ JrJackson, and OkJson.
82
55
  email:
83
56
  - michael@intridea.com
84
57
  - josh.kalderimis@gmail.com
85
58
  - sferik@gmail.com
59
+ - pavel@pravosud.com
86
60
  executables: []
87
61
  extensions: []
88
- extra_rdoc_files:
89
- - LICENSE.md
90
- - README.md
62
+ extra_rdoc_files: []
91
63
  files:
64
+ - CHANGELOG.md
65
+ - CONTRIBUTING.md
92
66
  - LICENSE.md
93
67
  - README.md
94
- - Rakefile
95
- - multi_json.gemspec
96
- - Gemfile
97
- - .document
98
- - .rspec
99
- - .travis.yml
100
- - spec/adapter_shared_example.rb
101
- - spec/helper.rb
102
- - spec/multi_json_spec.rb
68
+ - lib/multi_json.rb
69
+ - lib/multi_json/adapter.rb
70
+ - lib/multi_json/adapter_error.rb
71
+ - lib/multi_json/adapters/gson.rb
72
+ - lib/multi_json/adapters/jr_jackson.rb
103
73
  - lib/multi_json/adapters/json_common.rb
104
74
  - lib/multi_json/adapters/json_gem.rb
105
75
  - lib/multi_json/adapters/json_pure.rb
@@ -107,37 +77,36 @@ files:
107
77
  - lib/multi_json/adapters/oj.rb
108
78
  - lib/multi_json/adapters/ok_json.rb
109
79
  - lib/multi_json/adapters/yajl.rb
80
+ - lib/multi_json/convertible_hash_keys.rb
81
+ - lib/multi_json/options.rb
82
+ - lib/multi_json/options_cache.rb
83
+ - lib/multi_json/parse_error.rb
110
84
  - lib/multi_json/vendor/okjson.rb
111
85
  - lib/multi_json/version.rb
112
- - lib/multi_json.rb
86
+ - multi_json.gemspec
113
87
  homepage: http://github.com/intridea/multi_json
114
88
  licenses:
115
89
  - MIT
90
+ metadata: {}
116
91
  post_install_message:
117
- rdoc_options:
118
- - --charset=UTF-8
92
+ rdoc_options: []
119
93
  require_paths:
120
94
  - lib
121
95
  required_ruby_version: !ruby/object:Gem::Requirement
122
96
  requirements:
123
- - - ! '>='
97
+ - - ">="
124
98
  - !ruby/object:Gem::Version
125
99
  version: '0'
126
- none: false
127
100
  required_rubygems_version: !ruby/object:Gem::Requirement
128
101
  requirements:
129
- - - ! '>='
102
+ - - ">="
130
103
  - !ruby/object:Gem::Version
131
- version: 1.3.6
132
- none: false
104
+ version: 1.3.5
133
105
  requirements: []
134
106
  rubyforge_project:
135
- rubygems_version: 1.8.23
107
+ rubygems_version: 2.6.4
136
108
  signing_key:
137
- specification_version: 3
138
- summary: A gem to provide swappable JSON backends.
139
- test_files:
140
- - spec/adapter_shared_example.rb
141
- - spec/helper.rb
142
- - spec/multi_json_spec.rb
109
+ specification_version: 4
110
+ summary: A common interface to multiple JSON libraries.
111
+ test_files: []
143
112
  has_rdoc:
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ {�:����E�VL���?>c4o�p
data/.document DELETED
@@ -1,5 +0,0 @@
1
- LICENSE.md
2
- README.md
3
- bin/*
4
- features/**/*.feature
5
- lib/**/*.rb
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --fail-fast
3
- --order random
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - rbx-18mode
4
- - rbx-19mode
5
- - jruby-18mode
6
- - jruby-19mode
7
- - 1.8.7
8
- - 1.9.2
9
- - 1.9.3
10
- - ruby-head
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'json', '~> 1.4', :require => nil
4
- gem 'oj', '~> 1.0', :require => nil, :platforms => [:ruby, :mswin, :mingw]
5
- gem 'yajl-ruby', '~> 1.0', :require => nil, :platforms => [:ruby, :mswin, :mingw]
6
-
7
- gemspec
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
- desc "Run all examples"
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task :default => :spec
9
- task :test => :spec
10
-
11
- namespace :doc do
12
- require 'rdoc/task'
13
- require File.expand_path('../lib/multi_json/version', __FILE__)
14
- RDoc::Task.new do |rdoc|
15
- rdoc.rdoc_dir = 'rdoc'
16
- rdoc.title = "multi_json #{MultiJson::VERSION}"
17
- rdoc.main = 'README.md'
18
- rdoc.rdoc_files.include('README.md', 'LICENSE.md', 'lib/**/*.rb')
19
- end
20
- end