File: json_common.rb

package info (click to toggle)
ruby-multi-json 1.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 180 kB
  • sloc: ruby: 845; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 584 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module MultiJson
  module Adapters
    module JsonCommon

      def load(string, options={})
        string = string.read if string.respond_to?(:read)
        ::JSON.parse(string, :symbolize_names => options[:symbolize_keys])
      end

      def dump(object, options={})
        object.to_json(process_options(options))
      end

    protected

      def process_options(options={})
        return options if options.empty?
        opts = {}
        opts.merge!(JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
        opts.merge!(options)
      end

    end
  end
end