Sha256: 1286242c89deb4765f68f21887fc3f1f4f6c3b265df1466b512af14f8abb813d

Contents?: true

Size: 1.21 KB

Versions: 33

Compression:

Stored size: 1.21 KB

Contents

require 'singleton'
require 'multi_json/options'

module MultiJson
  class Adapter
    extend Options
    include Singleton

    class << self
      def defaults(action, value)
        metaclass = class << self; self; end

        metaclass.instance_eval do
          define_method("default_#{action}_options") { value }
        end
      end

      def load(string, options = {})
        fail self::ParseError if blank?(string)
        string = string.read if string.respond_to?(:read)
        instance.load(string, cached_load_options(options))
      end

      def dump(object, options = {})
        instance.dump(object, cached_dump_options(options))
      end

    private

      def blank?(input)
        input.nil? || /\A\s*\z/ === input
      rescue ArgumentError # invalid byte sequence in UTF-8
        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

Version data entries

33 entries across 32 versions & 11 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
mercadopago-custom-checkout-0.1.2 .gs/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
mercadopago-custom-checkout-0.1.1 .gs/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
tdiary-5.0.5 vendor/bundle/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
tdiary-5.0.4 vendor/bundle/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
arcabouco-0.2.13 vendor/bundle/gems/multi_json-1.12.1/lib/multi_json/adapter.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb