Class: Ulock::Interface
- Inherits:
-
Object
- Object
- Ulock::Interface
- Defined in:
- lib/ulock.rb
Instance Method Summary collapse
- #any? ⇒ Boolean
- #decrypt(filename) ⇒ Object
- #encrypt(filename) ⇒ Object
- #fix_all ⇒ Object
- #get_recipient! ⇒ Object
-
#initialize(recipient = nil) ⇒ Interface
constructor
A new instance of Interface.
- #interactive ⇒ Object
- #shorthelp ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(recipient = nil) ⇒ Interface
Returns a new instance of Interface.
60 61 62 |
# File 'lib/ulock.rb', line 60 def initialize(recipient=nil) @recipient = recipient end |
Instance Method Details
#any? ⇒ Boolean
94 95 96 |
# File 'lib/ulock.rb', line 94 def any? Ulock.missing_encrypted_version.any? || Ulock.missing_decrypted_version.any? end |
#decrypt(filename) ⇒ Object
117 118 119 120 |
# File 'lib/ulock.rb', line 117 def decrypt(filename) PROMPT.say "decrypting #{encrypted_filename} to #{encrypted_filename.gsub('.gpg', '')}" Ulock.decrypt_file(filename) end |
#encrypt(filename) ⇒ Object
111 112 113 114 115 |
# File 'lib/ulock.rb', line 111 def encrypt(filename) get_recipient! PROMPT.say "adding an encrypted version of #{filename} (r: #{recipient})" Ulock.encrypt_file(filename, @recipient) end |
#fix_all ⇒ Object
104 105 106 107 108 109 |
# File 'lib/ulock.rb', line 104 def fix_all get_recipient! PROMPT.say "Encrypting and Decrypting all the files" Ulock.encrypt_multiple(Ulock.missing_encrypted_version, @recipient) Ulock.decrypt_multiple(Ulock.missing_decrypted_version) end |
#get_recipient! ⇒ Object
98 99 100 101 102 |
# File 'lib/ulock.rb', line 98 def get_recipient! if !@recipient @recipient = PROMPT.ask("Encryption recipient: ") end end |
#interactive ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/ulock.rb', line 130 def interactive get_recipient! to_encrypt = prompt_encrypt to_decrypt = prompt_decrypt Ulock.encrypt_multiple(to_encrypt, @recipient) Ulock.decrypt_multiple(to_decrypt) end |
#shorthelp ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/ulock.rb', line 85 def shorthelp if any? PROMPT.say "#{$0} fix all #encrypt and decrypt all", color: :red PROMPT.say "#{$0} interactive #encrypt and decrypt interactively", color: :red end PROMPT.say "#{$0} --help #for more", color: :red end |
#status ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ulock.rb', line 64 def status ef = Ulock.missing_decrypted_version if ef.any? PROMPT.say "#{ef.count} files to be decrypted:", color: :bright_magenta PROMPT.say ef.join("\n"), color: :magenta puts "\n" else PROMPT.say "No files to be decrypted" end df = Ulock.missing_encrypted_version if df.any? PROMPT.say "#{df.count} files to be encrypted: \r", color: :bright_blue PROMPT.say df.join("\n"), color: :blue puts "\n" else PROMPT.say "No files to be encrypted" end end |