Class: Timert::DatabaseFile
- Inherits:
-
Object
- Object
- Timert::DatabaseFile
- Defined in:
- lib/timert/database_file.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ DatabaseFile
constructor
A new instance of DatabaseFile.
- #load ⇒ Object
- #save(hash) ⇒ Object
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
#load ⇒ Object
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 |