/usr/lib/ruby/vendor_ruby/yajl/json_gem/encoding.rb is in ruby-yajl 1.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | require 'yajl' unless defined?(Yajl::Parser)
# NOTE: this is probably temporary until I can split out the JSON compat C code into it's own
# extension that can be included when this file is.
Yajl::Encoder.enable_json_gem_compatability
# Our fallback to_json definition
unless defined?(ActiveSupport)
class Object
def to_json(*args, &block)
"\"#{to_s}\""
end
end
end
module JSON
class JSONError < StandardError; end unless defined?(JSON::JSONError)
class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
def self.generate(obj, opts=nil)
opts ||= {}
options_map = {}
if opts.has_key?(:indent)
options_map[:pretty] = true
options_map[:indent] = opts[:indent]
end
Yajl::Encoder.encode(obj, options_map)
rescue Yajl::EncodeError => e
raise JSON::GeneratorError, e.message
end
def self.pretty_generate(obj, opts={})
begin
options_map = {}
options_map[:pretty] = true
options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
Yajl::Encoder.encode(obj, options_map)
rescue Yajl::EncodeError => e
raise JSON::GeneratorError, e.message
end
end
def self.dump(obj, io=nil, *args)
begin
Yajl::Encoder.encode(obj, io)
rescue Yajl::EncodeError => e
raise JSON::GeneratorError, e.message
end
end
end
|