Class: Lockness::EncryptedFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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_pathObject



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

Returns:

  • (Boolean)


10
11
12
# File 'lib/lockness/encrypted_file.rb', line 10

def exist?
  File.exist?(encrypted_path)
end

#readObject



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_pathObject



14
15
16
# File 'lib/lockness/encrypted_file.rb', line 14

def unencrypted_path
  path.chomp('.enc')
end