Class: Ubiquitously::Storage::FileSystem
- Defined in:
- lib/ubiquitously/support/storage.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ FileSystem
constructor
A new instance of FileSystem.
- #load ⇒ Object
- #read(path) ⇒ Object
- #save(cookies, credentials) ⇒ Object
- #write(path, content) ⇒ Object
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
#path ⇒ Object
Returns the value of attribute path.
18 19 20 |
# File 'lib/ubiquitously/support/storage.rb', line 18 def path @path end |
Instance Method Details
#load ⇒ Object
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(, credentials) write("#{path}/cookies.yml", ) 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 |