Class: Lockness::EncryptedFile
- Inherits:
-
Object
- Object
- Lockness::EncryptedFile
- Defined in:
- lib/lockness/encrypted_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #encrypted_path ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(path:) ⇒ EncryptedFile
constructor
A new instance of EncryptedFile.
- #read ⇒ Object
- #save(encrypted_content) ⇒ Object
- #unencrypted_path ⇒ Object
Constructor Details
#initialize(path:) ⇒ EncryptedFile
Returns a new instance of EncryptedFile.
6 7 8 |
# File 'lib/lockness/encrypted_file.rb', line 6 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/lockness/encrypted_file.rb', line 4 def path @path end |
Instance Method Details
#encrypted_path ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/lockness/encrypted_file.rb', line 18 def encrypted_path if path.ends_with?('.enc') path else "#{path}.enc" end end |
#exist? ⇒ Boolean
10 11 12 |
# File 'lib/lockness/encrypted_file.rb', line 10 def exist? File.exist?(encrypted_path) end |
#read ⇒ Object
26 27 28 29 30 |
# File 'lib/lockness/encrypted_file.rb', line 26 def read return unless exist? File.read(encrypted_path) end |
#save(encrypted_content) ⇒ Object
32 33 34 |
# File 'lib/lockness/encrypted_file.rb', line 32 def save(encrypted_content) File.write(encrypted_path, encrypted_content) end |
#unencrypted_path ⇒ Object
14 15 16 |
# File 'lib/lockness/encrypted_file.rb', line 14 def unencrypted_path path.chomp('.enc') end |