Module: JSON

Defined in:
lib/nosj/json.rb

Overview

Reopened by require "nosj/json" to reroute the module functions through NOSJ; behavior is documented on the require and in the README, not here.

Instance Method Summary collapse

Instance Method Details

#dump(obj, an_io = nil, limit = nil, kwargs = nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/nosj/json.rb', line 104

def dump(obj, an_io = nil, limit = nil, kwargs = nil)
  # Fast path for the common shapes, dump(obj) and dump(obj, opts
  # hash), mirroring the gem: dump defaults merged under the
  # user's options, NestingError surfaced as ArgumentError. IO and
  # limit arguments take the original implementation.
  if limit.nil? && kwargs.nil? && (an_io.nil? || an_io.instance_of?(Hash))
    opts = _dump_default_options
    opts = opts.merge(an_io) if an_io
    if NOSJ::JSONDropIn.supported?(opts, NOSJ::JSONDropIn::GENERATE_OPTS)
      begin
        return NOSJ::JSONDropIn.generate(obj, opts, false)
      rescue ::JSON::NestingError
        raise ArgumentError, "exceed depth limit"
      end
    end
  end
  nosj_original_dump(obj, an_io, limit, kwargs)
end

#generate(obj, opts = nil) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/nosj/json.rb', line 88

def generate(obj, opts = nil)
  if NOSJ::JSONDropIn.supported?(opts, NOSJ::JSONDropIn::GENERATE_OPTS)
    NOSJ::JSONDropIn.generate(obj, opts, false)
  else
    nosj_original_generate(obj, opts)
  end
end

#nosj_original_dumpObject



78
# File 'lib/nosj/json.rb', line 78

alias_method :nosj_original_dump, :dump

#nosj_original_generateObject



76
# File 'lib/nosj/json.rb', line 76

alias_method :nosj_original_generate, :generate

#nosj_original_parseObject



75
# File 'lib/nosj/json.rb', line 75

alias_method :nosj_original_parse, :parse

#nosj_original_pretty_generateObject



77
# File 'lib/nosj/json.rb', line 77

alias_method :nosj_original_pretty_generate, :pretty_generate

#parse(source, opts = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/nosj/json.rb', line 80

def parse(source, opts = nil)
  if NOSJ::JSONDropIn.supported?(opts, NOSJ::JSONDropIn::PARSE_OPTS)
    NOSJ::JSONDropIn.parse(source, opts)
  else
    nosj_original_parse(source, opts)
  end
end

#pretty_generate(obj, opts = nil) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/nosj/json.rb', line 96

def pretty_generate(obj, opts = nil)
  if NOSJ::JSONDropIn.supported?(opts, NOSJ::JSONDropIn::GENERATE_OPTS)
    NOSJ::JSONDropIn.generate(obj, opts, true)
  else
    nosj_original_pretty_generate(obj, opts)
  end
end