Method: Keybox::Application::PasswordSafe#list
- Defined in:
- lib/keybox/application/password_safe.rb
#list(account) ⇒ Object
list all the entries in the database. This doesn’t show the password for any of them, just lists the key information about each entry so the user can see what is in the database
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/keybox/application/password_safe.rb', line 325 def list(account) matches = @db.find(account) title = "Title" username = "Username" add_info = "Additional Information" if matches.size > 0 then lengths = { :title => (matches.collect { |f| f.title.length } << title.length).max, :username => (matches.collect { |f| f.username.length } << username.length).max, :additional_info => add_info.length } full_length = lengths.values.inject(0) { |sum,n| sum + n} header = " # #{"Title".ljust(lengths[:title])} #{"Username".ljust(lengths[:username])} #{add_info}" hsay header, :header # 3 spaces for number column + 1 space after and 4 spaces between # each other column hsay"-" * (header.length), :header_bar matches.each_with_index do |match,i| line_number = sprintf("%3d", i + 1) # toggle colors color = [:even_row, :odd_row][i % 2] columns = [] [:title, :username, :additional_info].each do |f| t = match.send(f) t = "-" if t.nil? or t.length == 0 columns << t.ljust(lengths[f]) end cdata = columns.join(" " * 4) @highline.say("<%= color('#{line_number}',:line_number) %> <%= color(%Q{#{cdata}},'#{color}') %>") end else hsay "No matching records were found.", :information end end |