Class: CloudEncryptedSync::Adapters::Filesystem
- Inherits:
-
Template
- Object
- Template
- CloudEncryptedSync::Adapters::Filesystem
- Defined in:
- lib/adapters/filesystem.rb
Instance Attribute Summary collapse
-
#storage_path ⇒ Object
Returns the value of attribute storage_path.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #key_exists?(key) ⇒ Boolean
- #parse_command_line_options(parser) ⇒ Object
- #read(key) ⇒ Object
- #write(data, key) ⇒ Object
Instance Attribute Details
#storage_path ⇒ Object
Returns the value of attribute storage_path.
4 5 6 |
# File 'lib/adapters/filesystem.rb', line 4 def storage_path @storage_path end |
Instance Method Details
#delete(key) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/adapters/filesystem.rb', line 24 def delete(key) if key_exists?(key) File.delete(storage_path_to(key)) else raise Errors::NoSuchKey.new(key) end end |
#key_exists?(key) ⇒ Boolean
32 33 34 |
# File 'lib/adapters/filesystem.rb', line 32 def key_exists?(key) File.exist?(storage_path_to(key)) end |
#parse_command_line_options(parser) ⇒ Object
6 7 8 9 10 |
# File 'lib/adapters/filesystem.rb', line 6 def (parser) parser.on('--storage-path PATH', 'Path to folder where encrypted files are/will be stored.') do |storage| self.storage_path = storage end end |
#read(key) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/adapters/filesystem.rb', line 16 def read(key) if key_exists?(key) File.read(storage_path_to(key)) else raise Errors::NoSuchKey.new(key) end end |
#write(data, key) ⇒ Object
12 13 14 |
# File 'lib/adapters/filesystem.rb', line 12 def write(data, key) File.open(storage_path_to(key),'w') { |file| file.write(data) } end |