Module: Ulock

Defined in:
lib/ulock.rb,
lib/version.rb

Defined Under Namespace

Classes: Interface

Constant Summary collapse

PROMPT =
TTY::Prompt.new
EXCLUDE_EXTENSIONS =
['.md', '.txt']
VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.decrypt_file(encrypted_filename) ⇒ Object



35
36
37
38
# File 'lib/ulock.rb', line 35

def decrypt_file(encrypted_filename)
  dest_filename = encrypted_filename.gsub('.gpg', '')
  `gpg -d #{encrypted_filename} > #{dest_filename}`
end

.decrypt_multiple(filenames) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/ulock.rb', line 40

def decrypt_multiple(filenames)
  bar = TTY::ProgressBar.new("Decrypting :filename [:bar]", total: filenames.length * 5)
  filenames.each do |file|
    decrypt_file file
    bar.advance 5, filename: file
  end
  bar.finish
end

.encrypt_file(filename, recipient) ⇒ Object



31
32
33
# File 'lib/ulock.rb', line 31

def encrypt_file(filename, recipient)
  `gpg -r #{recipient} -e #{filename}`
end

.encrypt_multiple(filenames, recipient) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/ulock.rb', line 49

def encrypt_multiple(filenames, recipient)
  bar = TTY::ProgressBar.new("Encrypting :filename [:bar]", total: filenames.length * 5)
  filenames.each do |file|
    bar.advance 5, filename: file
    encrypt_file file, recipient
  end
  bar.finish
end

.encrypted_filesObject



12
13
14
# File 'lib/ulock.rb', line 12

def encrypted_files
  files('**/*.gpg')
end

.files(glob) ⇒ Object



8
9
10
# File 'lib/ulock.rb', line 8

def files(glob)
  Dir.glob(glob).reject { |f| File.directory?(f) }
end

.missing_decrypted_versionObject



21
22
23
24
# File 'lib/ulock.rb', line 21

def missing_decrypted_version
  of = other_files
  encrypted_files.select { |filename| !of.include?(filename.gsub(/.gpg/, '')) }
end

.missing_encrypted_versionObject



26
27
28
29
# File 'lib/ulock.rb', line 26

def missing_encrypted_version
  ef = encrypted_files
  other_files.select { |filename| !ef.include?(filename + '.gpg') }
end

.other_filesObject



16
17
18
19
# File 'lib/ulock.rb', line 16

def other_files
  glb = "**/*[!.gpg,#{EXCLUDE_EXTENSIONS.join(",")}]"
  files(glb) 
end