Class: XCCache::JSONRepresentable

Inherits:
HashRepresentable show all
Defined in:
lib/xccache/core/syntax/json.rb

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Instance Method Summary collapse

Methods inherited from HashRepresentable

#[], #[]=, #initialize, #merge!

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Instance Method Details

#loadObject



6
7
8
9
10
# File 'lib/xccache/core/syntax/json.rb', line 6

def load
  JSON.parse(path.read) if path.exist?
rescue StandardError
  {}
end

#save(to: nil) ⇒ Object



12
13
14
# File 'lib/xccache/core/syntax/json.rb', line 12

def save(to: nil)
  (to || path).write(JSON.pretty_generate(raw))
end