Module: SimpleCov::JSON

Defined in:
lib/simplecov/json.rb

Class Method Summary collapse

Class Method Details

.dump(string) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/simplecov/json.rb', line 14

def dump(string)
  if defined? ::JSON
    ::JSON.pretty_generate(string)
  else
    # Detect and use available MultiJson API - it changed in v1.3
    if MultiJson.respond_to?(:adapter)
      MultiJson.dump(string)
    else
      MultiJson.encode(string)
    end
  end
end

.parse(json) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/simplecov/json.rb', line 5

def parse(json)
  # Detect and use available MultiJson API - it changed in v1.3
  if MultiJson.respond_to?(:adapter)
    MultiJson.load(json)
  else
    MultiJson.decode(json)
  end
end