Class: GitReport::Storage

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

Instance Method Summary collapse

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

#loadObject

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