class Posgra::Identifier::Auto
Public Class Methods
new(output, options = {})
click to toggle source
# File lib/posgra/identifier/auto.rb, line 2 def initialize(output, options = {}) @output = output @options = options end
Public Instance Methods
identify(user)
click to toggle source
# File lib/posgra/identifier/auto.rb, line 7 def identify(user) password = mkpasswd((@options[:password_length] || 8).to_i) puts_password(user, password) password end
Private Instance Methods
mkpasswd(len)
click to toggle source
# File lib/posgra/identifier/auto.rb, line 15 def mkpasswd(len) sources = [ (1..9).to_a, ('A'..'Z').to_a, ('a'..'z').to_a, ].shuffle passwd = [] len.times do |i| src = sources[i % sources.length] passwd << src.shuffle.shift end passwd.join end
open_output() { |$stdout| ... }
click to toggle source
# File lib/posgra/identifier/auto.rb, line 38 def open_output return if @options[:dry_run] if @output == '-' yield($stdout) $stdout.flush else open(@output, 'a') do |f| yield(f) f.flush end end end
puts_password(user, password)
click to toggle source
# File lib/posgra/identifier/auto.rb, line 32 def puts_password(user, password) open_output do |f| f.puts("#{user},#{password}") end end