[DRE-commits] [ruby-multi-json] 01/05: New upstream version 1.12.1

Lucas Nussbaum lucas at moszumanska.debian.org
Sat Jul 1 23:13:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

lucas pushed a commit to branch master
in repository ruby-multi-json.

commit 348e12fd9ed736e59dbcd2b975353ec6fd15e7bb
Author: Lucas Nussbaum <lucas at debian.org>
Date:   Sat Jul 1 23:19:52 2017 +0200

    New upstream version 1.12.1
---
 .travis.yml                                    | 11 +++--
 CHANGELOG.md                                   | 10 ++++
 Gemfile                                        |  5 +-
 README.md                                      |  4 +-
 Rakefile                                       |  4 +-
 benchmark.rb                                   | 11 +++++
 certs/rwz.pem                                  | 30 ++++++------
 lib/multi_json.rb                              | 65 ++++++++++++++------------
 lib/multi_json/adapter.rb                      | 25 +++++++---
 lib/multi_json/adapters/gson.rb                |  4 +-
 lib/multi_json/adapters/jr_jackson.rb          |  4 +-
 lib/multi_json/adapters/json_common.rb         |  4 +-
 lib/multi_json/adapters/nsjsonserialization.rb | 13 +++---
 lib/multi_json/adapters/oj.rb                  |  6 +--
 lib/multi_json/adapters/ok_json.rb             |  4 +-
 lib/multi_json/adapters/yajl.rb                |  4 +-
 lib/multi_json/convertible_hash_keys.rb        |  2 +-
 lib/multi_json/options.rb                      |  9 ++--
 lib/multi_json/options_cache.rb                | 29 ++++++++++++
 lib/multi_json/vendor/okjson.rb                | 10 ++--
 lib/multi_json/version.rb                      | 11 ++---
 multi_json.gemspec                             | 28 +++++------
 spec/jr_jackson_adapter_spec.rb                |  2 +-
 spec/json_gem_adapter_spec.rb                  |  2 +-
 spec/json_pure_adapter_spec.rb                 |  2 +-
 spec/multi_json_spec.rb                        | 57 +++++++++++-----------
 spec/nsjsonserialization_adapter_spec.rb       |  2 +-
 spec/oj_adapter_spec.rb                        |  4 +-
 spec/ok_json_adapter_spec.rb                   |  2 +-
 spec/options_cache_spec.rb                     | 20 ++++++++
 spec/shared/adapter.rb                         | 55 +++++++++++-----------
 spec/shared/json_common_adapter.rb             |  6 +--
 spec/shared/options.rb                         | 20 ++++----
 spec/spec_helper.rb                            | 16 +++----
 spec/yajl_adapter_spec.rb                      |  2 +-
 35 files changed, 281 insertions(+), 202 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 3b198f3..019f7fe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,21 +1,24 @@
 bundler_args: --without development
+cache: bundler
 language: ruby
 rvm:
+  - jruby-18mode
+  - jruby-19mode
+  - jruby-9000
   - 1.8.7
   - 1.9.2
   - 1.9.3
   - 2.0.0
   - 2.1
-  - 2.2
-  - jruby-18mode
-  - jruby-19mode
+  - 2.2.4
+  - 2.3.1
   - jruby-head
   - rbx-2
   - ruby-head
 matrix:
   allow_failures:
-    - rvm: rbx-2
     - rvm: jruby-head
+    - rvm: rbx-2
     - rvm: ruby-head
   fast_finish: true
 sudo: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aeba82f..8b98307 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+1.12.1
+------
+
+* [Prevent meory leak in OptionsCache](https://github.com/intridea/multi_json/commit/aa7498199ad272f3d4a13750d7c568a66047e2ee)
+
+1.12.0
+------
+
+* [Introduce global options cache to improve peroformance](https://github.com/intridea/multi_json/commit/7aaef2a1bc2b83c95e4208b12dad5d1d87ff20a6)
+
 1.11.2
 ------
 
diff --git a/Gemfile b/Gemfile
index c9f631b..4b03311 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,12 +1,13 @@
 source 'https://rubygems.org'
 
-gem 'rake', '>= 0.9'
+gem 'rake', '~> 10.5'
 gem 'yard', '>= 0.8'
 
 gem 'json',      '~> 1.4', :require => nil
 gem 'json_pure', '~> 1.4', :require => nil
 
 group :development do
+  gem 'benchmark-ips'
   gem 'kramdown', '>= 0.14'
   gem 'pry'
 end
@@ -17,7 +18,7 @@ end
 
 platforms :jruby do
   gem 'gson', '>= 0.6', :require => nil
-  gem 'jrjackson', '~> 0.2.2', :require => nil
+  gem 'jrjackson', '~> 0.3.4', :require => nil
 end
 
 platforms :mingw, :mswin, :ruby do
diff --git a/README.md b/README.md
index 7f94341..ee8b86e 100644
--- a/README.md
+++ b/README.md
@@ -72,7 +72,9 @@ implementations:
 * Ruby 1.9.2
 * Ruby 1.9.3
 * Ruby 2.0.0
-* Ruby 2.1.1
+* Ruby 2.1
+* Ruby 2.2.4
+* Ruby 2.3.1
 * [JRuby][]
 * [Rubinius][]
 * [MacRuby][] (not tested on Travis CI)
diff --git a/Rakefile b/Rakefile
index e84074e..4a72846 100644
--- a/Rakefile
+++ b/Rakefile
@@ -3,7 +3,7 @@ Bundler::GemHelper.install_tasks
 
 require 'rspec/core/rake_task'
 RSpec::Core::RakeTask.new(:base_spec) do |task|
-  task.pattern = 'spec/multi_json_spec.rb'
+  task.pattern = 'spec/multi_json_spec.rb,spec/options_cache_spec.rb'
 end
 
 namespace :adapters do
@@ -16,7 +16,7 @@ namespace :adapters do
   end
 end
 
-task :spec => %w[base_spec adapters:oj adapters:yajl adapters:json_gem adapters:json_pure adapters:ok_json adapters:gson adapters:jr_jackson adapters:nsjsonserialization]
+task :spec => %w(base_spec adapters:oj adapters:yajl adapters:json_gem adapters:json_pure adapters:ok_json adapters:gson adapters:jr_jackson adapters:nsjsonserialization)
 
 task :default => :spec
 task :test => :spec
diff --git a/benchmark.rb b/benchmark.rb
new file mode 100644
index 0000000..1dd89cd
--- /dev/null
+++ b/benchmark.rb
@@ -0,0 +1,11 @@
+require 'oj'
+require 'multi_json'
+require 'benchmark/ips'
+
+MultiJson.use :oj
+
+Benchmark.ips do |x|
+  x.time = 10
+  x.warmup = 1
+  x.report { MultiJson.load(MultiJson.dump(a: 1, b: 2, c: 3)) }
+end
diff --git a/certs/rwz.pem b/certs/rwz.pem
index ae6951f..7d84ca5 100644
--- a/certs/rwz.pem
+++ b/certs/rwz.pem
@@ -1,21 +1,21 @@
 -----BEGIN CERTIFICATE-----
 MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVwYXZl
 bDEYMBYGCgmSJomT8ixkARkWCHByYXZvc3VkMRMwEQYKCZImiZPyLGQBGRYDY29t
-MB4XDTE1MDMwNDA0MTAzNVoXDTE2MDMwMzA0MTAzNVowPzEOMAwGA1UEAwwFcGF2
+MB4XDTE2MDQyNDIyMDk1MVoXDTE3MDQyNDIyMDk1MVowPzEOMAwGA1UEAwwFcGF2
 ZWwxGDAWBgoJkiaJk/IsZAEZFghwcmF2b3N1ZDETMBEGCgmSJomT8ixkARkWA2Nv
-bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKgJODgg1dH3weeyKtQF
-mhC3C8gleHSTZYAt1pMBZQ6QmRD7/kLIfLTJB/zgFUVoNoHVZ8qyFmx89reqk5Z4
-x/rIVskzpB76MushyaEJhw5UrxEZvoCK0b+nSUR8NT0YcznkjSbALBBagny5NWHn
-98LbVtIQYXdJTgC8xvV1u2Bix1JI/Qv1wuDKCw14XF2AFmT4nPt40FEUk4zWwbGI
-rdKjssA43TGDjzKmzdOpJ4aOble+Zq6N7jBacMdlsqQAvQ0bbGLokp8W7Ci/UNWC
-Q8DwDrjlbURMu729T70yuswrQHyxmh7SISMmjp44+C5ElwVbfcCQQxiwsdAcE3zD
-ST0CAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFJ7X
-Ly29ycziHHerLL3NCavLRSv5MB0GA1UdEQQWMBSBEnBhdmVsQHByYXZvc3VkLmNv
+bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK+YCSpSUOeZvxOyp0Zm
+DhlQ9Kc8ZxgaB3ekCS6lp7hV+eE6nZ84j4RLEqhfx0Vffx+yCmSx0lWum6eY9aOy
+rr+uCtiSiL+HR7t6KHqQ5myXwIvT7B+SqMYw8223fMFZMUit73PfTaMlIon+EsZB
+9TWzVU7MSRIHLr8P92/kExOuDhVcqFgmz+pWLeZjCk7r0JI0vxacFEK+ONjXThHk
+W1IRwy8qaFNiUdnIfTRgZV45T/PHzuLttdkgySTDQkZp198t9Y0m0eEDhpPjHNlr
+KoXtqUIqk1lmgsKKrOj4vsSX004v869GT45C4qR4/Oa2OyUsWiPf8N3GCYDBnK9C
+RDcCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFKm/
+jUdmc0kO/erio7IwB4zhYGmxMB0GA1UdEQQWMBSBEnBhdmVsQHByYXZvc3VkLmNv
 bTAdBgNVHRIEFjAUgRJwYXZlbEBwcmF2b3N1ZC5jb20wDQYJKoZIhvcNAQEFBQAD
-ggEBAJM/D4S0IHFerw9xcEKR2sehNn9deQKsS7auR3wAtxEitrPzKZb+8Uy3KVqP
-Jt/z5WABxO2Bjd7IM+s445lZF6kDsGsYYydlEkf9yzOYrtVmISTJYrsApU8BZQfL
-bWJg8zt1qjAKmmwULsCiYOfIGhUIhKVdVKrlkdXFFCB5v8R124FZXjo43WXZ2OCp
-4W7nHEaaaZLxrPnZCAiaryoFUL06d78sxq9F4MYfSD4CLdwJjNb5TOrwVAXK9uE9
-88AJhXqiqrY/cm2sh/xcGvGkhy9YOMyMZZrCAq4ruaXAB+tAkMrJ1paJDJRgErvJ
-8Vss1khfU5E/Xig1ytdFyNPPkCA=
+ggEBAGZprwh9PfxTaukluduGO2NWJpI5NC7A/OpoVFrtLTlMKDeoPvCgmNdSejS3
+6CyH8P3SI3OEkymRnLtQiJeQ//WDb7QPPQDPG0ZuxAylc35ITz7jTPAFC41AoTWM
+eSDWXP6yq0Gi6vlcvyIoBrvfFRPsg/gGhUp5DYKDLYzaEjNE30bME9fwDvlab7XR
+v4so5Zmmcof+9apAoaXDtj7HijhJWJcia8GWN5ycuDX38qMcpSU9/PF84s567W6e
+De8xFEGqLG8vclcTv7gGjDJH5FJTXuwLg41wc8p4ONXEBgLiaC7+S/DVDXWpYxuB
+akI17ua4eRKTFNvBtzP1802SP1k=
 -----END CERTIFICATE-----
diff --git a/lib/multi_json.rb b/lib/multi_json.rb
index 865c204..02c7250 100644
--- a/lib/multi_json.rb
+++ b/lib/multi_json.rb
@@ -2,40 +2,41 @@ require 'multi_json/options'
 require 'multi_json/version'
 require 'multi_json/adapter_error'
 require 'multi_json/parse_error'
+require 'multi_json/options_cache'
 
 module MultiJson
   include Options
   extend self
 
   def default_options=(value)
-    Kernel.warn "MultiJson.default_options setter is deprecated\n" +
-      "Use MultiJson.load_options and MultiJson.dump_options instead"
+    Kernel.warn "MultiJson.default_options setter is deprecated\n" \
+      'Use MultiJson.load_options and MultiJson.dump_options instead'
 
     self.load_options = self.dump_options = value
   end
 
   def default_options
-    Kernel.warn "MultiJson.default_options is deprecated\n" +
-      "Use MultiJson.load_options or MultiJson.dump_options instead"
+    Kernel.warn "MultiJson.default_options is deprecated\n" \
+      'Use MultiJson.load_options or MultiJson.dump_options instead'
 
-    self.load_options
+    load_options
   end
 
-  %w[cached_options reset_cached_options!].each do |method_name|
+  %w(cached_options reset_cached_options!).each do |method_name|
     define_method method_name do |*|
       Kernel.warn "MultiJson.#{method_name} method is deprecated and no longer used."
     end
   end
 
-  ALIASES = { 'jrjackson' => 'jr_jackson' }
+  ALIASES = {'jrjackson' => 'jr_jackson'}
 
   REQUIREMENT_MAP = [
-    ['oj',           :oj],
-    ['yajl',         :yajl],
-    ['jrjackson',    :jr_jackson],
-    ['json/ext',     :json_gem],
-    ['gson',         :gson],
-    ['json/pure',    :json_pure]
+    [:oj,         'oj'],
+    [:yajl,       'yajl'],
+    [:jr_jackson, 'jrjackson'],
+    [:json_gem,   'json/ext'],
+    [:gson,       'gson'],
+    [:json_pure,  'json/pure'],
   ]
 
   # The default adapter based on what you currently
@@ -49,7 +50,7 @@ module MultiJson
     return :json_gem if defined?(::JSON::JSON_LOADED)
     return :gson if defined?(::Gson)
 
-    REQUIREMENT_MAP.each do |library, adapter|
+    REQUIREMENT_MAP.each do |adapter, library|
       begin
         require library
         return adapter
@@ -58,22 +59,22 @@ module MultiJson
       end
     end
 
-    Kernel.warn '[WARNING] MultiJson is using the default adapter (ok_json).' +
+    Kernel.warn '[WARNING] MultiJson is using the default adapter (ok_json). ' \
       'We recommend loading a different JSON library to improve performance.'
 
     :ok_json
   end
-  alias default_engine default_adapter
+  alias_method :default_engine, :default_adapter
 
   # Get the current adapter class.
   def adapter
     return @adapter if defined?(@adapter) && @adapter
 
-    self.use nil # load default adapter
+    use nil # load default adapter
 
     @adapter
   end
-  alias engine adapter
+  alias_method :engine, :adapter
 
   # Set the JSON parser utilizing a symbol, string, or class.
   # Supported by default are:
@@ -88,9 +89,11 @@ module MultiJson
   # * <tt>:jr_jackson</tt> (JRuby only)
   def use(new_adapter)
     @adapter = load_adapter(new_adapter)
+  ensure
+    OptionsCache.reset
   end
-  alias adapter= use
-  alias engine= use
+  alias_method :adapter=, :use
+  alias_method :engine=, :use
 
   def load_adapter(new_adapter)
     case new_adapter
@@ -101,7 +104,7 @@ module MultiJson
     when Class, Module
       new_adapter
     else
-      raise ::LoadError, new_adapter
+      fail ::LoadError, new_adapter
     end
   rescue ::LoadError => exception
     raise AdapterError.build(exception)
@@ -113,7 +116,7 @@ module MultiJson
   #
   # <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
   # <tt>:adapter</tt> :: If set, the selected adapter will be used for this call.
-  def load(string, options={})
+  def load(string, options = {})
     adapter = current_adapter(options)
     begin
       adapter.load(string, options)
@@ -121,10 +124,10 @@ module MultiJson
       raise ParseError.build(exception, string)
     end
   end
-  alias decode load
+  alias_method :decode, :load
 
-  def current_adapter(options={})
-    if new_adapter = options[:adapter]
+  def current_adapter(options = {})
+    if (new_adapter = options[:adapter])
       load_adapter(new_adapter)
     else
       adapter
@@ -132,21 +135,22 @@ module MultiJson
   end
 
   # Encodes a Ruby object as JSON.
-  def dump(object, options={})
+  def dump(object, options = {})
     current_adapter(options).dump(object, options)
   end
-  alias encode dump
+  alias_method :encode, :dump
 
   #  Executes passed block using specified adapter.
   def with_adapter(new_adapter)
-    old_adapter, self.adapter = adapter, new_adapter
+    old_adapter = adapter
+    self.adapter = new_adapter
     yield
   ensure
     self.adapter = old_adapter
   end
-  alias with_engine with_adapter
+  alias_method :with_engine, :with_adapter
 
-  private
+private
 
   def load_adapter_from_string_name(name)
     name = ALIASES.fetch(name, name)
@@ -154,5 +158,4 @@ module MultiJson
     klass_name = name.to_s.split('_').map(&:capitalize) * ''
     MultiJson::Adapters.const_get(klass_name)
   end
-
 end
diff --git a/lib/multi_json/adapter.rb b/lib/multi_json/adapter.rb
index 19a7941..1d54d9a 100644
--- a/lib/multi_json/adapter.rb
+++ b/lib/multi_json/adapter.rb
@@ -5,24 +5,24 @@ module MultiJson
   class Adapter
     extend Options
     include Singleton
-    class << self
 
+    class << self
       def defaults(action, value)
         metaclass = class << self; self; end
 
         metaclass.instance_eval do
-          define_method("default_#{action}_options"){ value }
+          define_method("default_#{action}_options") { value }
         end
       end
 
-      def load(string, options={})
-        raise self::ParseError if blank?(string)
+      def load(string, options = {})
+        fail self::ParseError if blank?(string)
         string = string.read if string.respond_to?(:read)
-        instance.load(string, load_options(options).merge(MultiJson.load_options(options)).merge!(options))
+        instance.load(string, cached_load_options(options))
       end
 
-      def dump(object, options={})
-        instance.dump(object, dump_options(options).merge(MultiJson.dump_options(options)).merge!(options))
+      def dump(object, options = {})
+        instance.dump(object, cached_dump_options(options))
       end
 
     private
@@ -33,6 +33,17 @@ module MultiJson
         false
       end
 
+      def cached_dump_options(options)
+        OptionsCache.fetch(:dump, options) do
+          dump_options(options).merge(MultiJson.dump_options(options)).merge!(options)
+        end
+      end
+
+      def cached_load_options(options)
+        OptionsCache.fetch(:load, options) do
+          load_options(options).merge(MultiJson.load_options(options)).merge!(options)
+        end
+      end
     end
   end
 end
diff --git a/lib/multi_json/adapters/gson.rb b/lib/multi_json/adapters/gson.rb
index 0716b84..797fbf4 100644
--- a/lib/multi_json/adapters/gson.rb
+++ b/lib/multi_json/adapters/gson.rb
@@ -8,11 +8,11 @@ module MultiJson
     class Gson < Adapter
       ParseError = ::Gson::DecodeError
 
-      def load(string, options={})
+      def load(string, options = {})
         ::Gson::Decoder.new(options).decode(string)
       end
 
-      def dump(object, options={})
+      def dump(object, options = {})
         ::Gson::Encoder.new(options).encode(object)
       end
     end
diff --git a/lib/multi_json/adapters/jr_jackson.rb b/lib/multi_json/adapters/jr_jackson.rb
index edebdd7..a7e6cd8 100644
--- a/lib/multi_json/adapters/jr_jackson.rb
+++ b/lib/multi_json/adapters/jr_jackson.rb
@@ -7,7 +7,7 @@ module MultiJson
     class JrJackson < Adapter
       ParseError = ::JrJackson::ParseError
 
-      def load(string, options={}) #:nodoc:
+      def load(string, options = {}) #:nodoc:
         ::JrJackson::Json.load(string, options)
       end
 
@@ -16,7 +16,7 @@ module MultiJson
           ::JrJackson::Json.dump(object)
         end
       else
-        def dump(object, options={})
+        def dump(object, options = {})
           ::JrJackson::Json.dump(object, options)
         end
       end
diff --git a/lib/multi_json/adapters/json_common.rb b/lib/multi_json/adapters/json_common.rb
index 0fa03bd..e188895 100644
--- a/lib/multi_json/adapters/json_common.rb
+++ b/lib/multi_json/adapters/json_common.rb
@@ -5,7 +5,7 @@ module MultiJson
     class JsonCommon < Adapter
       defaults :load, :create_additions => false, :quirks_mode => true
 
-      def load(string, options={})
+      def load(string, options = {})
         if string.respond_to?(:force_encoding)
           string = string.dup.force_encoding(::Encoding::ASCII_8BIT)
         end
@@ -14,7 +14,7 @@ module MultiJson
         ::JSON.parse(string, options)
       end
 
-      def dump(object, options={})
+      def dump(object, options = {})
         options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
         object.to_json(options)
       end
diff --git a/lib/multi_json/adapters/nsjsonserialization.rb b/lib/multi_json/adapters/nsjsonserialization.rb
index 2603051..207b0e2 100644
--- a/lib/multi_json/adapters/nsjsonserialization.rb
+++ b/lib/multi_json/adapters/nsjsonserialization.rb
@@ -6,28 +6,27 @@ module MultiJson
     class Nsjsonserialization < MultiJson::Adapters::OkJson
       ParseError = ::MultiJson::OkJson::Error
 
-      def load(string, options={})
+      def load(string, options = {})
         data = string.dataUsingEncoding(NSUTF8StringEncoding)
-        object = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, error: nil)
+        object = NSJSONSerialization.JSONObjectWithData(data, :options => NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, :error => nil)
         if object
           object = symbolize_keys(object) if options[:symbolize_keys]
           object
         else
-          super(string, options={})
+          super(string, options)
         end
       end
 
-      def dump(object, options={})
+      def dump(object, options = {})
         pretty = options[:pretty] ? NSJSONWritingPrettyPrinted : 0
         object = object.as_json if object.respond_to?(:as_json)
         if NSJSONSerialization.isValidJSONObject(object)
-          data = NSJSONSerialization.dataWithJSONObject(object, options: pretty, error: nil)
-          NSMutableString.alloc.initWithData(data, encoding: NSUTF8StringEncoding)
+          data = NSJSONSerialization.dataWithJSONObject(object, :options => pretty, :error => nil)
+          NSMutableString.alloc.initWithData(data, :encoding => NSUTF8StringEncoding)
         else
           super(object, options)
         end
       end
-
     end
   end
 end
diff --git a/lib/multi_json/adapters/oj.rb b/lib/multi_json/adapters/oj.rb
index 44301d9..7d6c1f8 100644
--- a/lib/multi_json/adapters/oj.rb
+++ b/lib/multi_json/adapters/oj.rb
@@ -10,12 +10,12 @@ module MultiJson
 
       ParseError = defined?(::Oj::ParseError) ? ::Oj::ParseError : SyntaxError
 
-      def load(string, options={})
-        options[:symbol_keys] = options.delete(:symbolize_keys)
+      def load(string, options = {})
+        options[:symbol_keys] = options[:symbolize_keys]
         ::Oj.load(string, options)
       end
 
-      def dump(object, options={})
+      def dump(object, options = {})
         options.merge!(:indent => 2) if options[:pretty]
         options[:indent] = options[:indent].to_i if options[:indent]
         ::Oj.dump(object, options)
diff --git a/lib/multi_json/adapters/ok_json.rb b/lib/multi_json/adapters/ok_json.rb
index cde63ce..7f51145 100644
--- a/lib/multi_json/adapters/ok_json.rb
+++ b/lib/multi_json/adapters/ok_json.rb
@@ -8,14 +8,14 @@ module MultiJson
       include ConvertibleHashKeys
       ParseError = ::MultiJson::OkJson::Error
 
-      def load(string, options={})
+      def load(string, options = {})
         result = ::MultiJson::OkJson.decode("[#{string}]").first
         options[:symbolize_keys] ? symbolize_keys(result) : result
       rescue ArgumentError # invalid byte sequence in UTF-8
         raise ParseError
       end
 
-      def dump(object, options={})
+      def dump(object, _ = {})
         ::MultiJson::OkJson.valenc(stringify_keys(object))
       end
     end
diff --git a/lib/multi_json/adapters/yajl.rb b/lib/multi_json/adapters/yajl.rb
index 34d5eeb..1c297a5 100644
--- a/lib/multi_json/adapters/yajl.rb
+++ b/lib/multi_json/adapters/yajl.rb
@@ -7,11 +7,11 @@ module MultiJson
     class Yajl < Adapter
       ParseError = ::Yajl::ParseError
 
-      def load(string, options={})
+      def load(string, options = {})
         ::Yajl::Parser.new(:symbolize_keys => options[:symbolize_keys]).parse(string)
       end
 
-      def dump(object, options={})
+      def dump(object, options = {})
         ::Yajl::Encoder.encode(object, options)
       end
     end
diff --git a/lib/multi_json/convertible_hash_keys.rb b/lib/multi_json/convertible_hash_keys.rb
index 71996b9..1253e66 100644
--- a/lib/multi_json/convertible_hash_keys.rb
+++ b/lib/multi_json/convertible_hash_keys.rb
@@ -1,6 +1,6 @@
 module MultiJson
   module ConvertibleHashKeys
-    private
+  private
 
     def symbolize_keys(hash)
       prepare_hash(hash) do |key|
diff --git a/lib/multi_json/options.rb b/lib/multi_json/options.rb
index c2162bb..a56a90e 100644
--- a/lib/multi_json/options.rb
+++ b/lib/multi_json/options.rb
@@ -1,11 +1,12 @@
 module MultiJson
   module Options
-
     def load_options=(options)
+      OptionsCache.reset
       @load_options = options
     end
 
     def dump_options=(options)
+      OptionsCache.reset
       @dump_options = options
     end
 
@@ -25,12 +26,12 @@ module MultiJson
       @default_dump_options ||= {}
     end
 
-    private
+  private
 
     def get_options(options, *args)
-      if options.respond_to?(:call) and options.arity
+      if options.respond_to?(:call) && options.arity
         options.arity == 0 ? options[] : options[*args]
-      elsif Hash === options or options.respond_to?(:to_hash)
+      elsif options.respond_to?(:to_hash)
         options.to_hash
       end
     end
diff --git a/lib/multi_json/options_cache.rb b/lib/multi_json/options_cache.rb
new file mode 100644
index 0000000..05bf59d
--- /dev/null
+++ b/lib/multi_json/options_cache.rb
@@ -0,0 +1,29 @@
+module MultiJson
+  module OptionsCache
+    extend self
+
+    def reset
+      @dump_cache = {}
+      @load_cache = {}
+    end
+
+    def fetch(type, key)
+      cache = instance_variable_get("@#{type}_cache")
+      cache.key?(key) ? cache[key] : write(cache, key, &Proc.new)
+    end
+
+    private
+
+    # Normally MultiJson is used with a few option sets for both dump/load
+    # methods. When options are generated dynamically though, every call would
+    # cause a cache miss and the cache would grow indefinitely. To prevent
+    # this, we just reset the cache every time the number of keys outgrows
+    # 1000.
+    MAX_CACHE_SIZE = 1000
+
+    def write(cache, key)
+      cache.clear if cache.length >= MAX_CACHE_SIZE
+      cache[key] = yield
+    end
+  end
+end
diff --git a/lib/multi_json/vendor/okjson.rb b/lib/multi_json/vendor/okjson.rb
index f026071..0d5f814 100644
--- a/lib/multi_json/vendor/okjson.rb
+++ b/lib/multi_json/vendor/okjson.rb
@@ -26,10 +26,10 @@ require 'stringio'
 
 module MultiJson
   # Some parts adapted from
-  # http://golang.org/src/pkg/json/decode.go and
-  # http://golang.org/src/pkg/utf8/utf8.go
+  # https://golang.org/src/encoding/json/decode.go and
+  # https://golang.org/src/unicode/utf8/utf8.go
   module OkJson
-    Upstream = '43'
+    Upstream = '45'
     extend self
 
 
@@ -266,14 +266,14 @@ module MultiJson
 
 
     def numtok(s)
-      m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
+      m = /(-?(?:[1-9][0-9]+|[0-9]))([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
       if m && m.begin(0) == 0
         if !m[2] && !m[3]
           [:val, m[0], Integer(m[0])]
         elsif m[2]
           [:val, m[0], Float(m[0])]
         else
-          [:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
+          [:val, m[0], Integer(m[1])*(10**m[3][1..-1].to_i(10))]
         end
       else
         []
diff --git a/lib/multi_json/version.rb b/lib/multi_json/version.rb
index 004b248..bc37e01 100644
--- a/lib/multi_json/version.rb
+++ b/lib/multi_json/version.rb
@@ -1,19 +1,16 @@
 module MultiJson
   class Version
-    MAJOR =  1 unless defined? MultiJson::Version::MAJOR
-    MINOR = 11 unless defined? MultiJson::Version::MINOR
-    PATCH =  2 unless defined? MultiJson::Version::PATCH
-    PRE =  nil unless defined? MultiJson::Version::PRE
+    MAJOR = 1 unless defined? MultiJson::Version::MAJOR
+    MINOR = 12 unless defined? MultiJson::Version::MINOR
+    PATCH = 1 unless defined? MultiJson::Version::PATCH
+    PRE = nil unless defined? MultiJson::Version::PRE
 
     class << self
-
       # @return [String]
       def to_s
         [MAJOR, MINOR, PATCH, PRE].compact.join('.')
       end
-
     end
-
   end
 
   VERSION = Version.to_s.freeze
diff --git a/multi_json.gemspec b/multi_json.gemspec
index 70f476c..e9de919 100644
--- a/multi_json.gemspec
+++ b/multi_json.gemspec
@@ -1,20 +1,20 @@
 # coding: utf-8
-require File.expand_path("../lib/multi_json/version.rb", __FILE__)
+require File.expand_path('../lib/multi_json/version.rb', __FILE__)
 
 Gem::Specification.new do |spec|
-  spec.authors       = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober", "Pavel Pravosud"]
-  spec.cert_chain    = %w[certs/rwz.pem]
-  spec.summary       = "A common interface to multiple JSON libraries."
-  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."
-  spec.email         = %w[michael at intridea.com josh.kalderimis at gmail.com sferik at gmail.com pavel at pravosud.com]
-  spec.files         = Dir["CHANGELOG.md", "CONTRIBUTING.md", "LICENSE.md", "README.md", "multi_json.gemspec", "lib/**/*"]
-  spec.homepage      = "http://github.com/intridea/multi_json"
-  spec.license       = "MIT"
-  spec.name          = "multi_json"
-  spec.require_path  = "lib"
-  spec.signing_key   = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
+  spec.authors       = ['Michael Bleigh', 'Josh Kalderimis', 'Erik Michaels-Ober', 'Pavel Pravosud']
+  spec.cert_chain    = %w(certs/rwz.pem)
+  spec.summary       = 'A common interface to multiple JSON libraries.'
+  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.'
+  spec.email         = %w(michael at intridea.com josh.kalderimis at gmail.com sferik at gmail.com pavel at pravosud.com)
+  spec.files         = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE.md', 'README.md', 'multi_json.gemspec', 'lib/**/*']
+  spec.homepage      = 'http://github.com/intridea/multi_json'
+  spec.license       = 'MIT'
+  spec.name          = 'multi_json'
+  spec.require_path  = 'lib'
+  spec.signing_key   = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
   spec.version       = MultiJson::Version
 
-  spec.required_rubygems_version = ">= 1.3.5"
-  spec.add_development_dependency "bundler", "~> 1.0"
+  spec.required_rubygems_version = '>= 1.3.5'
+  spec.add_development_dependency 'bundler', '~> 1.0'
 end
diff --git a/spec/jr_jackson_adapter_spec.rb b/spec/jr_jackson_adapter_spec.rb
index 0b80e61..e620f6e 100644
--- a/spec/jr_jackson_adapter_spec.rb
+++ b/spec/jr_jackson_adapter_spec.rb
@@ -7,4 +7,4 @@ require 'multi_json/adapters/jr_jackson'
 
 describe MultiJson::Adapters::JrJackson do
   it_behaves_like 'an adapter', described_class
-end
\ No newline at end of file
+end
diff --git a/spec/json_gem_adapter_spec.rb b/spec/json_gem_adapter_spec.rb
index 2c9f35d..f43eacb 100644
--- a/spec/json_gem_adapter_spec.rb
+++ b/spec/json_gem_adapter_spec.rb
@@ -6,4 +6,4 @@ require 'multi_json/adapters/json_gem'
 describe MultiJson::Adapters::JsonGem do
   it_behaves_like 'an adapter', described_class
   it_behaves_like 'JSON-like adapter', described_class
-end
\ No newline at end of file
+end
diff --git a/spec/json_pure_adapter_spec.rb b/spec/json_pure_adapter_spec.rb
index e1fc625..8280ace 100644
--- a/spec/json_pure_adapter_spec.rb
+++ b/spec/json_pure_adapter_spec.rb
@@ -6,4 +6,4 @@ require 'multi_json/adapters/json_pure'
 describe MultiJson::Adapters::JsonPure do
   it_behaves_like 'an adapter', described_class
   it_behaves_like 'JSON-like adapter', described_class
-end
\ No newline at end of file
+end
diff --git a/spec/multi_json_spec.rb b/spec/multi_json_spec.rb
index 22ac5c6..2f049f0 100644
--- a/spec/multi_json_spec.rb
+++ b/spec/multi_json_spec.rb
@@ -4,7 +4,7 @@ require 'shared/options'
 describe MultiJson do
   before(:all) do
     # make sure all available libs are required
-    MultiJson::REQUIREMENT_MAP.each do |library, adapter|
+    MultiJson::REQUIREMENT_MAP.each do |_, library|
       begin
         require library
       rescue ::LoadError
@@ -15,7 +15,7 @@ describe MultiJson do
 
   context 'when no other json implementations are available' do
     around do |example|
-      simulate_no_adapters{ example.call }
+      simulate_no_adapters { example.call }
     end
 
     it 'defaults to ok_json if no other json implementions are available' do
@@ -31,19 +31,19 @@ describe MultiJson do
   end
 
   context 'caching' do
-    before{ MultiJson.use adapter }
-    let(:adapter){ MultiJson::Adapters::JsonGem }
-    let(:json_string){ '{"abc":"def"}' }
+    before { MultiJson.use adapter }
+    let(:adapter) { MultiJson::Adapters::JsonGem }
+    let(:json_string) { '{"abc":"def"}' }
 
     it 'busts caches on global options change' do
-      MultiJson.load_options = { :symbolize_keys => true }
+      MultiJson.load_options = {:symbolize_keys => true}
       expect(MultiJson.load(json_string)).to eq(:abc => 'def')
       MultiJson.load_options = nil
       expect(MultiJson.load(json_string)).to eq('abc' => 'def')
     end
 
     it 'busts caches on per-adapter options change' do
-      adapter.load_options = { :symbolize_keys => true }
+      adapter.load_options = {:symbolize_keys => true}
       expect(MultiJson.load(json_string)).to eq(:abc => 'def')
       adapter.load_options = nil
       expect(MultiJson.load(json_string)).to eq('abc' => 'def')
@@ -90,14 +90,14 @@ describe MultiJson do
   end
 
   it 'throws AdapterError on bad input' do
-    expect{ MultiJson.use 'bad adapter' }.to raise_error(MultiJson::AdapterError, /bad adapter/)
+    expect { MultiJson.use 'bad adapter' }.to raise_error(MultiJson::AdapterError, /bad adapter/)
   end
 
   it 'gives access to original error when raising AdapterError' do
-    exception = get_exception(MultiJson::AdapterError){ MultiJson.use 'foobar' }
+    exception = get_exception(MultiJson::AdapterError) { MultiJson.use 'foobar' }
     expect(exception.cause).to be_instance_of(::LoadError)
-    expect(exception.message).to include("-- multi_json/adapters/foobar")
-    expect(exception.message).to include("Did not recognize your adapter specification")
+    expect(exception.message).to include('-- multi_json/adapters/foobar')
+    expect(exception.message).to include('Did not recognize your adapter specification')
   end
 
   context 'using one-shot parser' do
@@ -127,37 +127,37 @@ describe MultiJson do
 
   it 'JSON gem does not create symbols on parse' do
     MultiJson.with_engine(:json_gem) do
-      MultiJson.load('{"json_class":"ZOMG"}') rescue nil
+      MultiJson.load('{"json_class":"ZOMG"}')
 
-      expect{
-        MultiJson.load('{"json_class":"OMG"}') rescue nil
-      }.to_not change{Symbol.all_symbols.count}
+      expect do
+        MultiJson.load('{"json_class":"OMG"}')
+      end.to_not change { Symbol.all_symbols.count }
     end
   end
 
   unless jruby?
     it 'Oj does not create symbols on parse' do
       MultiJson.with_engine(:oj) do
-        MultiJson.load('{"json_class":"ZOMG"}') rescue nil
+        MultiJson.load('{"json_class":"ZOMG"}')
 
-        expect{
-          MultiJson.load('{"json_class":"OMG"}') rescue nil
-        }.to_not change{Symbol.all_symbols.count}
+        expect do
+          MultiJson.load('{"json_class":"OMG"}')
+        end.to_not change { Symbol.all_symbols.count }
       end
     end
 
     context 'with Oj.default_settings' do
       around do |example|
         options = Oj.default_options
-        Oj.default_options = { :symbol_keys => true }
-        MultiJson.with_engine(:oj){ example.call }
+        Oj.default_options = {:symbol_keys => true}
+        MultiJson.with_engine(:oj) { example.call }
         Oj.default_options = options
       end
 
       it 'ignores global settings' do
         MultiJson.with_engine(:oj) do
           example = '{"a": 1, "b": 2}'
-          expected = { 'a' => 1, 'b' => 2 }
+          expected = {'a' => 1, 'b' => 2}
           expect(MultiJson.load(example)).to eq(expected)
         end
       end
@@ -165,17 +165,17 @@ describe MultiJson do
   end
 
   describe 'default options' do
-    after(:all){ MultiJson.load_options = MultiJson.dump_options = nil }
+    after(:all) { MultiJson.load_options = MultiJson.dump_options = nil }
 
     it 'is deprecated' do
       expect(Kernel).to receive(:warn).with(/deprecated/i)
-      silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
+      silence_warnings { MultiJson.default_options = {:foo => 'bar'} }
     end
 
     it 'sets both load and dump options' do
       expect(MultiJson).to receive(:dump_options=).with(:foo => 'bar')
       expect(MultiJson).to receive(:load_options=).with(:foo => 'bar')
-      silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
+      silence_warnings { MultiJson.default_options = {:foo => 'bar'} }
     end
   end
 
@@ -184,16 +184,15 @@ describe MultiJson do
   describe 'aliases' do
     if jruby?
       describe 'jrjackson' do
-        after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
+        after { expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
 
         it 'allows jrjackson alias as symbol' do
-          expect{ MultiJson.use :jrjackson }.not_to raise_error
+          expect { MultiJson.use :jrjackson }.not_to raise_error
         end
 
         it 'allows jrjackson alias as string' do
-          expect{ MultiJson.use 'jrjackson' }.not_to raise_error
+          expect { MultiJson.use 'jrjackson' }.not_to raise_error
         end
-
       end
     end
   end
diff --git a/spec/nsjsonserialization_adapter_spec.rb b/spec/nsjsonserialization_adapter_spec.rb
index 302ecc6..76bca02 100644
--- a/spec/nsjsonserialization_adapter_spec.rb
+++ b/spec/nsjsonserialization_adapter_spec.rb
@@ -7,4 +7,4 @@ require 'multi_json/adapters/nsjsonserialization'
 
 describe MultiJson::Adapters::Nsjsonserialization do
   it_behaves_like 'an adapter', described_class
-end
\ No newline at end of file
+end
diff --git a/spec/oj_adapter_spec.rb b/spec/oj_adapter_spec.rb
index a76908c..a2a2668 100644
--- a/spec/oj_adapter_spec.rb
+++ b/spec/oj_adapter_spec.rb
@@ -10,10 +10,10 @@ describe MultiJson::Adapters::Oj do
 
   describe '.dump' do
     describe '#dump_options' do
-      around{ |example| with_default_options(&example) }
+      around { |example| with_default_options(&example) }
 
       it 'ensures indent is a Fixnum' do
-        expect{ MultiJson.dump(42, :indent => '')}.not_to raise_error
+        expect { MultiJson.dump(42, :indent => '') }.not_to raise_error
       end
     end
   end
diff --git a/spec/ok_json_adapter_spec.rb b/spec/ok_json_adapter_spec.rb
index 7bfdf11..f15d612 100644
--- a/spec/ok_json_adapter_spec.rb
+++ b/spec/ok_json_adapter_spec.rb
@@ -4,4 +4,4 @@ require 'multi_json/adapters/ok_json'
 
 describe MultiJson::Adapters::OkJson do
   it_behaves_like 'an adapter', described_class
-end
\ No newline at end of file
+end
diff --git a/spec/options_cache_spec.rb b/spec/options_cache_spec.rb
new file mode 100644
index 0000000..bc3dbeb
--- /dev/null
+++ b/spec/options_cache_spec.rb
@@ -0,0 +1,20 @@
+require "spec_helper"
+
+describe MultiJson::OptionsCache do
+  before { described_class.reset }
+
+  it "doesn't leak memory" do
+    described_class::MAX_CACHE_SIZE.succ.times do |i|
+      described_class.fetch(:dump, :key => i) do
+        { :foo => i }
+      end
+
+      described_class.fetch(:load, :key => i) do
+        { :foo => i }
+      end
+    end
+
+    expect(described_class.instance_variable_get(:@dump_cache).length).to eq(1)
+    expect(described_class.instance_variable_get(:@load_cache).length).to eq(1)
+  end
+end
diff --git a/spec/shared/adapter.rb b/spec/shared/adapter.rb
index 2405900..c77b87e 100644
--- a/spec/shared/adapter.rb
+++ b/spec/shared/adapter.rb
@@ -3,20 +3,19 @@
 require 'shared/options'
 
 shared_examples_for 'an adapter' do |adapter|
-
-  before{ MultiJson.use adapter }
+  before { MultiJson.use adapter }
 
   it_behaves_like 'has options', adapter
 
   it 'does not modify argument hashes' do
-    options = { :symbolize_keys => true, :pretty => false, :adapter => :ok_json }
-    expect{MultiJson.load('{}', options)}.to_not change{options}
-    expect{MultiJson.dump([42], options)}.to_not change{options}
+    options = {:symbolize_keys => true, :pretty => false, :adapter => :ok_json}
+    expect { MultiJson.load('{}', options) }.to_not change { options }
+    expect { MultiJson.dump([42], options) }.to_not change { options }
   end
 
   describe '.dump' do
     describe '#dump_options' do
-      before{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
+      before { MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
 
       after do
         expect(MultiJson.adapter.instance).to receive(:dump).with(1, :foo => 'bar', :fizz => 'buzz')
@@ -46,7 +45,7 @@ shared_examples_for 'an adapter' do |adapter|
         '2',
         true,
         false,
-        nil
+        nil,
       ]
 
       examples.each do |example|
@@ -56,13 +55,15 @@ shared_examples_for 'an adapter' do |adapter|
 
     unless 'json_pure' == adapter || 'json_gem' == adapter
       it 'dumps time in correct format' do
-        time = Time.at(1355218745).utc
+        time = Time.at(1_355_218_745).utc
 
         dumped_json = MultiJson.dump(time)
-        expected = if RUBY_VERSION > '1.9'
-          '2012-12-11 09:39:05 UTC'
-        else
-          'Tue Dec 11 09:39:05 UTC 2012'
+        expected = begin
+          if RUBY_VERSION > '1.9'
+            '2012-12-11 09:39:05 UTC'
+          else
+            'Tue Dec 11 09:39:05 UTC 2012'
+          end
         end
         expect(MultiJson.load(dumped_json)).to eq(expected)
       end
@@ -84,8 +85,8 @@ shared_examples_for 'an adapter' do |adapter|
         ],
         [
           {1 => {2 => {3 => 'bar'}}},
-          {'1' => {'2' => {'3' => 'bar'}}}
-        ]
+          {'1' => {'2' => {'3' => 'bar'}}},
+        ],
       ].each do |example, expected|
         dumped_json = MultiJson.dump(example)
         expect(MultiJson.load(dumped_json)).to eq(expected)
@@ -98,7 +99,7 @@ shared_examples_for 'an adapter' do |adapter|
     end
 
     it 'passes options to the adapter' do
-      expect(MultiJson.adapter).to receive(:dump).with('foo', {:bar => :baz})
+      expect(MultiJson.adapter).to receive(:dump).with('foo', :bar => :baz)
       MultiJson.dump('foo', :bar => :baz)
     end
 
@@ -123,7 +124,7 @@ shared_examples_for 'an adapter' do |adapter|
 
   describe '.load' do
     describe '#load_options' do
-      before{ MultiJson.load_options = MultiJson.adapter.load_options = {} }
+      before { MultiJson.load_options = MultiJson.adapter.load_options = {} }
 
       after do
         expect(MultiJson.adapter.instance).to receive(:load).with('1', :foo => 'bar', :fizz => 'buzz')
@@ -146,22 +147,21 @@ shared_examples_for 'an adapter' do |adapter|
     end
 
     it 'does not modify input' do
-      input = %Q{\n\n  {"foo":"bar"} \n\n\t}
-      expect{
+      input = %(\n\n  {"foo":"bar"} \n\n\t)
+      expect do
         MultiJson.load(input)
-      }.to_not change{ input }
+      end.to_not change { input }
     end
 
     # Ruby 1.8 doesn't support String encodings
     if RUBY_VERSION > '1.9'
       it 'does not modify input encoding' do
-
         input = '[123]'
         input.force_encoding('iso-8859-1')
 
-        expect{
+        expect do
           MultiJson.load(input)
-        }.to_not change{ input.encoding }
+        end.to_not change { input.encoding }
       end
     end
 
@@ -175,32 +175,31 @@ shared_examples_for 'an adapter' do |adapter|
           pending 'GSON bug: https://github.com/avsej/gson.rb/issues/3' if adapter.name =~ /Gson/
         end
 
-        expect{MultiJson.load(input)}.to raise_error(MultiJson::ParseError)
+        expect { MultiJson.load(input) }.to raise_error(MultiJson::ParseError)
       end
     end
 
     it 'raises MultiJson::ParseError with data on invalid JSON' do
       data = '{invalid}'
-      exception = get_exception(MultiJson::ParseError){ MultiJson.load data }
+      exception = get_exception(MultiJson::ParseError) { MultiJson.load data }
       expect(exception.data).to eq(data)
       expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
     end
 
     it 'catches MultiJson::DecodeError for legacy support' do
       data = '{invalid}'
-      exception = get_exception(MultiJson::DecodeError){ MultiJson.load data }
+      exception = get_exception(MultiJson::DecodeError) { MultiJson.load data }
       expect(exception.data).to eq(data)
       expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
     end
 
     it 'catches MultiJson::LoadError for legacy support' do
       data = '{invalid}'
-      exception = get_exception(MultiJson::LoadError){ MultiJson.load data }
+      exception = get_exception(MultiJson::LoadError) { MultiJson.load data }
       expect(exception.data).to eq(data)
       expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
     end
 
-
     it 'stringifys symbol keys when encoding' do
       dumped_json = MultiJson.dump(:a => 1, :b => {:c => 2})
       loaded_json = MultiJson.load(dumped_json)
@@ -225,7 +224,7 @@ shared_examples_for 'an adapter' do |adapter|
         [
           '{"abc":[{"def":"hgi"}]}',
           {:abc => [{:def => 'hgi'}]},
-        ]
+        ],
       ].each do |example, expected|
         expect(MultiJson.load(example, :symbolize_keys => true)).to eq(expected)
       end
diff --git a/spec/shared/json_common_adapter.rb b/spec/shared/json_common_adapter.rb
index 0003581..9597d90 100644
--- a/spec/shared/json_common_adapter.rb
+++ b/spec/shared/json_common_adapter.rb
@@ -1,8 +1,8 @@
 shared_examples_for 'JSON-like adapter' do |adapter|
-  before{ MultiJson.use adapter }
+  before { MultiJson.use adapter }
 
   describe '.dump' do
-    before{ MultiJson.dump_options = MultiJson.adapter.dump_options = nil }
+    before { MultiJson.dump_options = MultiJson.adapter.dump_options = nil }
 
     describe 'with :pretty option set to true' do
       it 'passes default pretty options' do
@@ -23,7 +23,7 @@ shared_examples_for 'JSON-like adapter' do |adapter|
 
   describe '.load' do
     it 'passes :quirks_mode option' do
-      expect(::JSON).to receive(:parse).with('[123]', {:quirks_mode => false, :create_additions => false})
+      expect(::JSON).to receive(:parse).with('[123]', :quirks_mode => false, :create_additions => false)
       MultiJson.load('[123]', :quirks_mode => false)
     end
   end
diff --git a/spec/shared/options.rb b/spec/shared/options.rb
index fa55b3d..d36b1bd 100644
--- a/spec/shared/options.rb
+++ b/spec/shared/options.rb
@@ -1,13 +1,11 @@
 shared_examples_for 'has options' do |object|
-
   if object.respond_to?(:call)
-    subject{ object.call }
+    subject { object.call }
   else
-    subject{ object }
+    subject { object }
   end
 
-  describe "dump options" do
-
+  describe 'dump options' do
     before do
       subject.dump_options = nil
     end
@@ -37,12 +35,12 @@ shared_examples_for 'has options' do |object|
     end
 
     it 'evaluates lambda returning options (with args)' do
-      subject.dump_options = lambda{ |a1, a2| { a1 => a2 }}
+      subject.dump_options = lambda { |a1, a2| {a1 => a2} }
       expect(subject.dump_options('1', '2')).to eq('1' => '2')
     end
 
     it 'evaluates lambda returning options (with no args)' do
-      subject.dump_options = lambda{{:foo => 'bar'}}
+      subject.dump_options = lambda { {:foo => 'bar'} }
       expect(subject.dump_options).to eq(:foo => 'bar')
     end
 
@@ -61,8 +59,7 @@ shared_examples_for 'has options' do |object|
     end
   end
 
-  describe "load options" do
-
+  describe 'load options' do
     before do
       subject.load_options = nil
     end
@@ -92,12 +89,12 @@ shared_examples_for 'has options' do |object|
     end
 
     it 'evaluates lambda returning options (with args)' do
-      subject.load_options = lambda{ |a1, a2| { a1 => a2 }}
+      subject.load_options = lambda { |a1, a2| {a1 => a2} }
       expect(subject.load_options('1', '2')).to eq('1' => '2')
     end
 
     it 'evaluates lambda returning options (with no args)' do
-      subject.load_options = lambda{{:foo => 'bar'}}
+      subject.load_options = lambda { {:foo => 'bar'} }
       expect(subject.load_options).to eq(:foo => 'bar')
     end
 
@@ -115,5 +112,4 @@ shared_examples_for 'has options' do |object|
       expect(subject.load_options).to eq(subject.default_load_options)
     end
   end
-
 end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6be565f..906169d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -41,14 +41,14 @@ end
 
 def break_requirements
   requirements = MultiJson::REQUIREMENT_MAP
-  MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
-    MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
+  MultiJson::REQUIREMENT_MAP.each_with_index do |(adapter, library), index|
+    MultiJson::REQUIREMENT_MAP[index] = [adapter, "foo/#{library}"]
   end
 
   yield
 ensure
-  requirements.each_with_index do |(library, adapter), index|
-    MultiJson::REQUIREMENT_MAP[index] = [library, adapter]
+  requirements.each_with_index do |(adapter, library), index|
+    MultiJson::REQUIREMENT_MAP[index] = [adapter, library]
   end
 end
 
@@ -61,11 +61,9 @@ def simulate_no_adapters
 end
 
 def get_exception(exception_class = StandardError)
-  begin
-    yield
-  rescue exception_class => exception
-    exception
-  end
+  yield
+rescue exception_class => exception
+  exception
 end
 
 def with_default_options
diff --git a/spec/yajl_adapter_spec.rb b/spec/yajl_adapter_spec.rb
index 224ec4b..b99f9f7 100644
--- a/spec/yajl_adapter_spec.rb
+++ b/spec/yajl_adapter_spec.rb
@@ -7,4 +7,4 @@ require 'multi_json/adapters/yajl'
 
 describe MultiJson::Adapters::Yajl do
   it_behaves_like 'an adapter', described_class
-end
\ No newline at end of file
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-multi-json.git



More information about the Pkg-ruby-extras-commits mailing list