Class: Trundle::InfoStore

Inherits:
Object
  • Object
show all
Defined in:
lib/trundle/info_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ InfoStore

Returns a new instance of InfoStore.



4
5
6
# File 'lib/trundle/info_store.rb', line 4

def initialize(path)
  @path = path
end

Instance Method Details

#contentObject



12
13
14
15
16
# File 'lib/trundle/info_store.rb', line 12

def content
  @content ||= JSON.parse(File.read(@path))
rescue Errno::ENOENT
  @content = {}
end

#content=(value) ⇒ Object



8
9
10
# File 'lib/trundle/info_store.rb', line 8

def content=(value)
  @content = value
end

#writeObject



18
19
20
21
22
# File 'lib/trundle/info_store.rb', line 18

def write
  File.open(@path, 'w') do |file|
    file.write(JSON.pretty_generate(content))
  end
end