class Gratan::Identifier::Auto
Public Class Methods
new(output, options = {})
click to toggle source
# File lib/gratan/identifier/auto.rb, line 2 def initialize(output, options = {}) @output = output @options = options @cache = {} end
Public Instance Methods
identify(user, host)
click to toggle source
# File lib/gratan/identifier/auto.rb, line 8 def identify(user, host) if @cache[user] password = @cache[user] else password = mkpasswd @cache[user] = password end puts_password(user, host, password) password end
Private Instance Methods
mkpasswd(len = 8)
click to toggle source
# File lib/gratan/identifier/auto.rb, line 22 def mkpasswd(len = 8) [*1..9, *'A'..'Z', *'a'..'z'].shuffle.slice(0, len).join end
open_output() { |$stdout| ... }
click to toggle source
# File lib/gratan/identifier/auto.rb, line 32 def open_output return if @options[:dry_run] if @output == '-' yield($stdout) $stdout.flush else open(@output, 'a') do |f| yield(f) end end end
puts_password(user, host, password)
click to toggle source
# File lib/gratan/identifier/auto.rb, line 26 def puts_password(user, host, password) open_output do |f| f.puts("#{user}@#{host},#{password}") end end