Module: NOSJ::JSONDropIn
- Defined in:
- lib/nosj/json.rb
Overview
Implementation detail of require "nosj/json".
Constant Summary collapse
- PARSE_OPTS =
%i[symbolize_names freeze max_nesting allow_nan allow_trailing_comma].freeze
- GENERATE_OPTS =
%i[indent space space_before object_nl array_nl max_nesting allow_nan ascii_only script_safe escape_slash strict depth buffer_initial_length].freeze
Class Method Summary collapse
- .generate(obj, opts, pretty) ⇒ Object
- .parse(source, opts) ⇒ Object
-
.supported?(opts, allowed) ⇒ Boolean
The fast path handles nil or a plain Hash whose every key NOSJ implements; anything else (JSON::State, exotic options, string keys) belongs to the original implementation.
Class Method Details
.generate(obj, opts, pretty) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/nosj/json.rb', line 58 def generate(obj, opts, pretty) pretty ? NOSJ.pretty_generate(obj, opts) : NOSJ.generate(obj, opts) rescue NOSJ::NestingError => e raise ::JSON::NestingError, e. rescue NOSJ::GeneratorError => e raise ::JSON::GeneratorError, e. end |
.parse(source, opts) ⇒ Object
52 53 54 55 56 |
# File 'lib/nosj/json.rb', line 52 def parse(source, opts) NOSJ.parse(source, opts) rescue RuntimeError => e raise ::JSON::ParserError, e. end |
.supported?(opts, allowed) ⇒ Boolean
The fast path handles nil or a plain Hash whose every key NOSJ implements; anything else (JSON::State, exotic options, string keys) belongs to the original implementation.
45 46 47 48 49 50 |
# File 'lib/nosj/json.rb', line 45 def supported?(opts, allowed) return true if opts.nil? return false unless opts.instance_of?(Hash) opts.each_key { |k| return false unless allowed.include?(k) } true end |