Class: Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/trakr/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path('../..', __FILE__), 'storage.yml'))
    @file = file
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



2
3
4
# File 'lib/trakr/storage.rb', line 2

def database
  @database
end

#fileObject

Returns the value of attribute file.



2
3
4
# File 'lib/trakr/storage.rb', line 2

def file
  @file
end

Instance Method Details

#loadObject



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