Class: Storage
- Inherits:
-
Object
- Object
- Storage
- Defined in:
- lib/trakr/storage.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file = File.join(File.expand_path('../..', __FILE__), 'storage.yml')) ⇒ Storage
constructor
A new instance of Storage.
- #load ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(file = File.join(File.expand_path('../..', __FILE__), 'storage.yml')) ⇒ Storage
Returns a new instance of Storage.
3 4 5 |
# File 'lib/trakr/storage.rb', line 3 def initialize(file=File.join(File.('../..', __FILE__), 'storage.yml')) @file = file end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
2 3 4 |
# File 'lib/trakr/storage.rb', line 2 def database @database end |
#file ⇒ Object
Returns the value of attribute file.
2 3 4 |
# File 'lib/trakr/storage.rb', line 2 def file @file end |
Instance Method Details
#load ⇒ Object
7 8 9 10 11 12 |
# File 'lib/trakr/storage.rb', line 7 def load @database = YAML.load_file(@file) if not @database @database = {} end end |
#write! ⇒ Object
14 15 16 |
# File 'lib/trakr/storage.rb', line 14 def write! File.open(@file,'w+') {|f| f.write(@database.to_yaml)} end |