Sha256: f5e2cc6d68da4a652c4debddf21c2975784f36c38cdfe4ec8be8f5db39342eab

Contents?: true

Size: 1.21 KB

Versions: 91

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 = {})
        string = string.read if string.respond_to?(:read)
        fail self::ParseError if blank?(string)
        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

91 entries across 76 versions & 14 rubygems

Version Path
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/multi_json-1.14.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/multi_json-1.14.1/lib/multi_json/adapter.rb
multi_json-1.14.1 lib/multi_json/adapter.rb
multi_json-1.14.0 lib/multi_json/adapter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
tdiary-5.0.8 vendor/bundle/gems/multi_json-1.13.1/lib/multi_json/adapter.rb