Class: RPass::Shell
Instance Method Summary collapse
- #cp(args) ⇒ Object
- #find_matches(string) ⇒ Object
- #get_match(index) ⇒ Object
-
#initialize(accounts, display: Display.new) ⇒ Shell
constructor
A new instance of Shell.
- #ls(args) ⇒ Object
- #matched_accounts(string) ⇒ Object
- #print(args) ⇒ Object
- #prompt ⇒ Object
- #reset_matches ⇒ Object
Constructor Details
Instance Method Details
#cp(args) ⇒ Object
32 33 34 |
# File 'lib/rpass/shell.rb', line 32 def cp(args) pbcopy < get_match(args[0]).password end |
#find_matches(string) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rpass/shell.rb', line 55 def find_matches(string) accounts.select do |account| matched = false %i{id name username password url group}.each do |method| matched ||= account.send(method).to_s =~ /#{string}/ break if matched end matched end end |
#get_match(index) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rpass/shell.rb', line 40 def get_match(index) index = index.to_i fail "No matched accounts" unless matches fail "No such index: #{index}" if index < 0 || index > matches.size - 1 matches[index] end |
#ls(args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rpass/shell.rb', line 21 def ls(args) string = args.size == 0 ? "." : args.first reset_matches i = 0 matched_accounts(string).each do |account| puts display.render_account(account, i) puts i += 1 end end |
#matched_accounts(string) ⇒ Object
51 52 53 |
# File 'lib/rpass/shell.rb', line 51 def matched_accounts(string) @matches ||= find_matches(string) end |
#print(args) ⇒ Object
36 37 38 |
# File 'lib/rpass/shell.rb', line 36 def print(args) puts get_match(args[0]).password end |
#prompt ⇒ Object
66 67 68 |
# File 'lib/rpass/shell.rb', line 66 def prompt "rpass" end |
#reset_matches ⇒ Object
47 48 49 |
# File 'lib/rpass/shell.rb', line 47 def reset_matches @matches = nil end |