multi_json 1.15.0 → 1.16.0

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.
@@ -1,14 +1,14 @@
1
1
  module MultiJson
2
2
  class Version
3
3
  MAJOR = 1 unless defined? MultiJson::Version::MAJOR
4
- MINOR = 15 unless defined? MultiJson::Version::MINOR
4
+ MINOR = 16 unless defined? MultiJson::Version::MINOR
5
5
  PATCH = 0 unless defined? MultiJson::Version::PATCH
6
6
  PRE = nil unless defined? MultiJson::Version::PRE
7
7
 
8
8
  class << self
9
9
  # @return [String]
10
10
  def to_s
11
- [MAJOR, MINOR, PATCH, PRE].compact.join('.')
11
+ [MAJOR, MINOR, PATCH, PRE].compact.join(".")
12
12
  end
13
13
  end
14
14
  end
data/lib/multi_json.rb CHANGED
@@ -1,69 +1,59 @@
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'
1
+ require_relative "multi_json/options"
2
+ require_relative "multi_json/version"
3
+ require_relative "multi_json/adapter_error"
4
+ require_relative "multi_json/parse_error"
5
+ require_relative "multi_json/options_cache"
6
6
 
7
7
  module MultiJson
8
8
  include Options
9
9
  extend self
10
10
 
11
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'
12
+ Kernel.warn "MultiJson.default_options setter is deprecated\nUse MultiJson.load_options and MultiJson.dump_options instead"
14
13
 
15
14
  self.load_options = self.dump_options = value
16
15
  end
17
16
 
18
17
  def default_options
19
- Kernel.warn "MultiJson.default_options is deprecated\n" \
20
- 'Use MultiJson.load_options or MultiJson.dump_options instead'
18
+ Kernel.warn "MultiJson.default_options is deprecated\nUse MultiJson.load_options or MultiJson.dump_options instead"
21
19
 
22
20
  load_options
23
21
  end
24
22
 
25
- %w(cached_options reset_cached_options!).each do |method_name|
23
+ %w[cached_options reset_cached_options!].each do |method_name|
26
24
  define_method method_name do |*|
27
25
  Kernel.warn "MultiJson.#{method_name} method is deprecated and no longer used."
28
26
  end
29
27
  end
30
28
 
31
- ALIASES = {'jrjackson' => 'jr_jackson'}
29
+ ALIASES = {"jrjackson" => "jr_jackson"}.freeze
32
30
 
33
- REQUIREMENT_MAP = [
34
- [:oj, 'oj'],
35
- [:yajl, 'yajl'],
36
- [:jr_jackson, 'jrjackson'],
37
- [:json_gem, 'json/ext'],
38
- [:gson, 'gson'],
39
- [:json_pure, 'json/pure'],
40
- ]
31
+ REQUIREMENT_MAP = {
32
+ oj: "oj",
33
+ yajl: "yajl",
34
+ jr_jackson: "jrjackson",
35
+ json_gem: "json",
36
+ gson: "gson",
37
+ json_pure: "json"
38
+ }.freeze
41
39
 
42
40
  # 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.
41
+ # have loaded and installed.
46
42
  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::Ext::Parser)
51
- return :gson if defined?(::Gson)
52
-
53
- REQUIREMENT_MAP.each do |adapter, library|
54
- begin
55
- require library
56
- return adapter
57
- rescue ::LoadError
58
- next
59
- end
43
+ adapter = loaded_adapter || installable_adapter
44
+ return adapter if adapter
45
+
46
+ @default_adapter_warning_shown ||= begin
47
+ Kernel.warn(
48
+ "[WARNING] MultiJson is using the default adapter (ok_json). " \
49
+ "We recommend loading a different JSON library to improve performance."
50
+ )
51
+ true
60
52
  end
61
53
 
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
54
  :ok_json
66
55
  end
56
+
67
57
  alias_method :default_engine, :default_adapter
68
58
 
69
59
  # Get the current adapter class.
@@ -84,7 +74,6 @@ module MultiJson
84
74
  # * <tt>:json_pure</tt>
85
75
  # * <tt>:ok_json</tt>
86
76
  # * <tt>:yajl</tt>
87
- # * <tt>:nsjsonserialization</tt> (MacRuby only)
88
77
  # * <tt>:gson</tt> (JRuby only)
89
78
  # * <tt>:jr_jackson</tt> (JRuby only)
90
79
  def use(new_adapter)
@@ -104,10 +93,10 @@ module MultiJson
104
93
  when Class, Module
105
94
  new_adapter
106
95
  else
107
- fail ::LoadError, new_adapter
96
+ raise ::LoadError, new_adapter
108
97
  end
109
- rescue ::LoadError => exception
110
- raise AdapterError.build(exception)
98
+ rescue ::LoadError => e
99
+ raise(AdapterError.build(e), cause: e)
111
100
  end
112
101
 
113
102
  # Decode a JSON string into Ruby.
@@ -120,8 +109,8 @@ module MultiJson
120
109
  adapter = current_adapter(options)
121
110
  begin
122
111
  adapter.load(string, options)
123
- rescue adapter::ParseError => exception
124
- raise ParseError.build(exception, string)
112
+ rescue adapter::ParseError => e
113
+ raise(ParseError.build(e, string), cause: e)
125
114
  end
126
115
  end
127
116
  alias_method :decode, :load
@@ -150,12 +139,34 @@ module MultiJson
150
139
  end
151
140
  alias_method :with_engine, :with_adapter
152
141
 
153
- private
142
+ private
143
+
144
+ # Checks for already loaded adapters and returns the first match
145
+ def loaded_adapter
146
+ return :oj if defined?(::Oj)
147
+ return :yajl if defined?(::Yajl)
148
+ return :jr_jackson if defined?(::JrJackson)
149
+ return :json_gem if defined?(::JSON::Ext::Parser)
150
+ return :gson if defined?(::Gson)
151
+
152
+ nil
153
+ end
154
+
155
+ # Attempts to load and return the first installable adapter
156
+ def installable_adapter
157
+ REQUIREMENT_MAP.each do |adapter, library|
158
+ require library
159
+ return adapter
160
+ rescue ::LoadError
161
+ next
162
+ end
163
+ nil
164
+ end
154
165
 
155
166
  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) * ''
167
+ normalized_name = ALIASES.fetch(name, name).to_s
168
+ require "multi_json/adapters/#{normalized_name.downcase}"
169
+ klass_name = normalized_name.split("_").map(&:capitalize).join
159
170
  MultiJson::Adapters.const_get(klass_name)
160
171
  end
161
172
  end
metadata CHANGED
@@ -1,54 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  - Josh Kalderimis
9
- - Erik Michaels-Ober
9
+ - Erik Berlin
10
10
  - Pavel Pravosud
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2020-07-10 00:00:00.000000000 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rake
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '10.5'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '10.5'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - "~>"
35
- - !ruby/object:Gem::Version
36
- version: '3.9'
37
- type: :development
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '3.9'
13
+ date: 1980-01-02 00:00:00.000000000 Z
14
+ dependencies: []
44
15
  description: A common interface to multiple JSON libraries, including Oj, Yajl, the
45
- JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb,
46
- JrJackson, and OkJson.
16
+ JSON gem (with C-extensions), gson, JrJackson, and OkJson.
47
17
  email:
48
- - michael@intridea.com
49
- - josh.kalderimis@gmail.com
50
18
  - sferik@gmail.com
51
- - pavel@pravosud.com
52
19
  executables: []
53
20
  extensions: []
54
21
  extra_rdoc_files: []
@@ -62,10 +29,8 @@ files:
62
29
  - lib/multi_json/adapter_error.rb
63
30
  - lib/multi_json/adapters/gson.rb
64
31
  - lib/multi_json/adapters/jr_jackson.rb
65
- - lib/multi_json/adapters/json_common.rb
66
32
  - lib/multi_json/adapters/json_gem.rb
67
33
  - lib/multi_json/adapters/json_pure.rb
68
- - lib/multi_json/adapters/nsjsonserialization.rb
69
34
  - lib/multi_json/adapters/oj.rb
70
35
  - lib/multi_json/adapters/ok_json.rb
71
36
  - lib/multi_json/adapters/yajl.rb
@@ -75,16 +40,16 @@ files:
75
40
  - lib/multi_json/parse_error.rb
76
41
  - lib/multi_json/vendor/okjson.rb
77
42
  - lib/multi_json/version.rb
78
- homepage: https://github.com/intridea/multi_json
43
+ homepage: https://github.com/sferik/multi_json
79
44
  licenses:
80
45
  - MIT
81
46
  metadata:
82
- bug_tracker_uri: https://github.com/intridea/multi_json/issues
83
- changelog_uri: https://github.com/intridea/multi_json/blob/v1.15.0/CHANGELOG.md
84
- documentation_uri: https://www.rubydoc.info/gems/multi_json/1.15.0
85
- source_code_uri: https://github.com/intridea/multi_json/tree/v1.15.0
86
- wiki_uri: https://github.com/intridea/multi_json/wiki
87
- post_install_message:
47
+ bug_tracker_uri: https://github.com/sferik/multi_json/issues
48
+ changelog_uri: https://github.com/sferik/multi_json/blob/v1.16.0/CHANGELOG.md
49
+ documentation_uri: https://www.rubydoc.info/gems/multi_json/1.16.0
50
+ rubygems_mfa_required: 'true'
51
+ source_code_uri: https://github.com/sferik/multi_json/tree/v1.16.0
52
+ wiki_uri: https://github.com/sferik/multi_json/wiki
88
53
  rdoc_options: []
89
54
  require_paths:
90
55
  - lib
@@ -92,15 +57,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
57
  requirements:
93
58
  - - ">="
94
59
  - !ruby/object:Gem::Version
95
- version: '0'
60
+ version: '3.2'
96
61
  required_rubygems_version: !ruby/object:Gem::Requirement
97
62
  requirements:
98
63
  - - ">="
99
64
  - !ruby/object:Gem::Version
100
- version: 1.3.5
65
+ version: '0'
101
66
  requirements: []
102
- rubygems_version: 3.0.3
103
- signing_key:
67
+ rubygems_version: 3.6.9
104
68
  specification_version: 4
105
69
  summary: A common interface to multiple JSON libraries.
106
70
  test_files: []
@@ -1,23 +0,0 @@
1
- require 'multi_json/adapter'
2
-
3
- module MultiJson
4
- module Adapters
5
- class JsonCommon < Adapter
6
- defaults :load, :create_additions => false, :quirks_mode => true
7
-
8
- def load(string, options = {})
9
- if string.respond_to?(:force_encoding)
10
- string = string.dup.force_encoding(::Encoding::ASCII_8BIT)
11
- end
12
-
13
- options[:symbolize_names] = true if options.delete(:symbolize_keys)
14
- ::JSON.parse(string, options)
15
- end
16
-
17
- def dump(object, options = {})
18
- options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
19
- object.to_json(options)
20
- end
21
- end
22
- end
23
- end
@@ -1,35 +0,0 @@
1
- # This adapter is here for legacy reasons. We can't really test it, so it's hard
2
- # to tell if it's even working properly. If you're still using it, please
3
- # consider migrating to any other adapter out there.
4
- framework 'Foundation'
5
- require 'multi_json/adapters/ok_json'
6
-
7
- module MultiJson
8
- module Adapters
9
- class Nsjsonserialization < MultiJson::Adapters::OkJson
10
- ParseError = ::MultiJson::OkJson::Error
11
-
12
- def load(string, options = {})
13
- data = string.dataUsingEncoding(NSUTF8StringEncoding)
14
- object = NSJSONSerialization.JSONObjectWithData(data, :options => NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, :error => nil)
15
- if object
16
- object = symbolize_keys(object) if options[:symbolize_keys]
17
- object
18
- else
19
- super(string, options)
20
- end
21
- end
22
-
23
- def dump(object, options = {})
24
- pretty = options[:pretty] ? NSJSONWritingPrettyPrinted : 0
25
- object = object.as_json if object.respond_to?(:as_json)
26
- if NSJSONSerialization.isValidJSONObject(object)
27
- data = NSJSONSerialization.dataWithJSONObject(object, :options => pretty, :error => nil)
28
- NSMutableString.alloc.initWithData(data, :encoding => NSUTF8StringEncoding)
29
- else
30
- super(object, options)
31
- end
32
- end
33
- end
34
- end
35
- end