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
- .decrypt_file(encrypted_filename) ⇒ Object
- .decrypt_multiple(filenames) ⇒ Object
- .encrypt_file(filename, recipient) ⇒ Object
- .encrypt_multiple(filenames, recipient) ⇒ Object
- .encrypted_files ⇒ Object
- .files(glob) ⇒ Object
- .missing_decrypted_version ⇒ Object
- .missing_encrypted_version ⇒ Object
- .other_files ⇒ Object
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) = TTY::ProgressBar.new("Decrypting :filename [:bar]", total: filenames.length * 5) filenames.each do |file| decrypt_file file .advance 5, filename: file end .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) = TTY::ProgressBar.new("Encrypting :filename [:bar]", total: filenames.length * 5) filenames.each do |file| .advance 5, filename: file encrypt_file file, recipient end .finish end |
.encrypted_files ⇒ Object
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_version ⇒ Object
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_version ⇒ Object
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_files ⇒ Object
16 17 18 19 |
# File 'lib/ulock.rb', line 16 def other_files glb = "**/*[!.gpg,#{EXCLUDE_EXTENSIONS.join(",")}]" files(glb) end |