Class: Ubiquitously::Storage::FileSystem

Inherits:
Base show all
Defined in:
lib/ubiquitously/support/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileSystem

Returns a new instance of FileSystem.



20
21
22
# File 'lib/ubiquitously/support/storage.rb', line 20

def initialize(path)
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



18
19
20
# File 'lib/ubiquitously/support/storage.rb', line 18

def path
  @path
end

Instance Method Details

#loadObject



29
30
31
32
33
34
# File 'lib/ubiquitously/support/storage.rb', line 29

def load
  {
    :cookies => read("#{path}/cookies.yml"),
    :credentials => read("#{path}/credentials.yml")
  }
end

#read(path) ⇒ Object



36
37
38
39
40
# File 'lib/ubiquitously/support/storage.rb', line 36

def read(path)
  result = File.exists?(path) ? YAML.load_file(path) : {}
  result = {} unless result.is_a?(Hash)
  result
end

#save(cookies, credentials) ⇒ Object



24
25
26
27
# File 'lib/ubiquitously/support/storage.rb', line 24

def save(cookies, credentials)
  write("#{path}/cookies.yml", cookies)
  write("#{path}/credentials.yml", credentials)
end

#write(path, content) ⇒ Object



42
43
44
# File 'lib/ubiquitously/support/storage.rb', line 42

def write(path, content)
  File.open(path, "w+") { |file| file.puts YAML.dump(content) }
end