Class: Timert::DatabaseFile

Inherits:
Object
  • Object
show all
Defined in:
lib/timert/database_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DatabaseFile

Returns a new instance of DatabaseFile.



6
7
8
# File 'lib/timert/database_file.rb', line 6

def initialize(path)
  @path = path
end

Instance Method Details

#loadObject



10
11
12
13
14
# File 'lib/timert/database_file.rb', line 10

def load
  File.open(@path, 'a+') do |file|
    file.size > 0 ? JSON.load(file) : {}
  end
end

#save(hash) ⇒ Object



16
17
18
# File 'lib/timert/database_file.rb', line 16

def save(hash)
  File.open(@path, 'w+') { |f| f.write(hash.to_json) }
end