Sha256: b2d1ba2bf2f77b33c38e44a77a8424670612f33159640470a6b20ddfa577b5d5

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 KB

Contents

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

Version data entries

19 entries across 19 versions & 8 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/lib/yajl/json_gem/encoding.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/lib/yajl/json_gem/encoding.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/lib/yajl/json_gem/encoding.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/lib/yajl/json_gem/encoding.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/yajl-ruby-1.4.3/lib/yajl/json_gem/encoding.rb
yajl-ruby-1.4.3 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.4.2 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.4.1 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.4.0 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.2.3 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.3.1 lib/yajl/json_gem/encoding.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/lib/yajl/json_gem/encoding.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/lib/yajl/json_gem/encoding.rb
yajl-ruby-1.2.2 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.3.0 lib/yajl/json_gem/encoding.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/yajl-ruby-1.2.1/lib/yajl/json_gem/encoding.rb
yajl-ruby-1.2.1 lib/yajl/json_gem/encoding.rb
yajl-ruby-1.2.0 lib/yajl/json_gem/encoding.rb
yajl-ruby-zenjoy-1.1.0 lib/yajl/json_gem/encoding.rb