Module: JSON

Defined in:
lib/usamin/overwrite.rb

Defined Under Namespace

Classes: LoadProcCaller

Class Method Summary collapse

Class Method Details

.generate(object, **options) ⇒ Object Also known as: fast_generate


7
8
9
# File 'lib/usamin/overwrite.rb', line 7

def self.generate(object, **options)
  options[:indent] ? Usamin.pretty_generate(object, indent: options[:indent]) : Usamin.generate(object)
end

.load(source, proc = nil, **options) ⇒ Object Also known as: restore


23
24
25
26
27
# File 'lib/usamin/overwrite.rb', line 23

def self.load(source, proc = nil, **options)
  ret = Usamin.parse(source, **options)
  LoadProcCaller.load_call_proc(ret, proc) if proc
  ret
end

.parse(source, **options) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/usamin/overwrite.rb', line 15

def self.parse(source, **options)
  begin
    Usamin.parse(source, symbolize_names: options[:symbolize_names])
  rescue Usamin::ParserError
    raise JSON::ParserError.new($!.message)
  end
end

.pretty_generate(object, **options) ⇒ Object


11
12
13
# File 'lib/usamin/overwrite.rb', line 11

def self.pretty_generate(object, **options)
  options[:indent] ? Usamin.pretty_generate(object, indent: options[:indent]) : Usamin.pretty_generate(object)
end