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
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/multi_json-1.15.0/lib/multi_json/adapter.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb