Class: GitReport::Storage
- Inherits:
-
Object
- Object
- GitReport::Storage
- Defined in:
- lib/storage.rb
Instance Method Summary collapse
-
#initialize(path, filename) ⇒ Storage
constructor
inits storage object.
-
#load ⇒ Object
loads locally stored data.
-
#save!(data) ⇒ Object
locally stores data.
Constructor Details
#initialize(path, filename) ⇒ Storage
inits storage object
7 8 9 10 |
# File 'lib/storage.rb', line 7 def initialize path, filename @path = path @filename = filename end |
Instance Method Details
#load ⇒ Object
loads locally stored data
20 21 22 23 24 25 26 27 |
# File 'lib/storage.rb', line 20 def load if File.exists?("#{@path}/#{@filename}") data = File.read "#{@path}/#{@filename}" Marshal.load(Base64.decode64(data)) rescue NameError else [] end end |
#save!(data) ⇒ Object
locally stores data
13 14 15 16 17 |
# File 'lib/storage.rb', line 13 def save! data File.open("#{@path}/#{@filename}", 'w+') do |file| file.write Base64.encode64(Marshal.dump(data)) end end |