Sha256: c819602c993e2224a73f9769f3973c880c76133605a7cc4444b345142a85929b

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

module MultiJson
  module Adapters
    module JsonCommon
      def load(string, options={})
        string = string.read if string.respond_to?(:read)
        ::JSON.parse("[#{string}]", process_load_options!(options)).first
      end

      def dump(object, options={})
        ::JSON.generate([object], process_dump_options!(options)).strip[1..-2]
      end

    protected

      def process_load_options!(options={})
        process_options!({:create_additions => false}, options) do |opts|
          opts.merge!(:symbolize_names => true) if options.delete(:symbolize_keys)
        end
      end

      def process_dump_options!(options={})
        process_options!({}, options) do |opts|
          opts.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
        end
      end

      def process_options!(default_options, options)
        return default_options if options.empty?
        yield default_options
        default_options.merge!(options)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
multi_json-1.6.0 lib/multi_json/adapters/json_common.rb