Class: Shale::Adapter::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/adapter/json.rb

Overview

JSON adapter

Class Method Summary collapse

Class Method Details

.dump(obj, **options) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize Hash into JSON

Parameters:

  • obj (Hash)

    Hash object

  • options (Hash)

Returns:

  • (String)


31
32
33
34
35
36
37
38
39
# File 'lib/shale/adapter/json.rb', line 31

def self.dump(obj, **options)
  json_options = options.except(:pretty)

  if options[:pretty]
    ::JSON.pretty_generate(obj, **json_options)
  else
    ::JSON.generate(obj, **json_options)
  end
end

.load(json, **options) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse JSON into Hash

Parameters:

  • json (String)

    JSON document

  • options (Hash)

Returns:

  • (Hash)


19
20
21
# File 'lib/shale/adapter/json.rb', line 19

def self.load(json, **options)
  ::JSON.parse(json, **options)
end