Sha256: 06ee3e60990d5d2b324a2d841f822efdffbe9ad09be085159d4959daf60fc569

Contents?: true

Size: 657 Bytes

Versions: 2

Compression:

Stored size: 657 Bytes

Contents

class Miam::PasswordManager
  def initialize(output, options = {})
    @output = output
    @options = options
  end

  def identify(user, type)
    password = mkpasswd
    puts_password(user, type, password)
    password
  end

  def puts_password(user, type, password)
    open_output do |f|
      f.puts("#{user},#{type},#{password}")
    end
  end

  private

  def mkpasswd(len = 8)
    [*1..9, *'A'..'Z', *'a'..'z'].shuffle.slice(0, len).join
  end

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
miam-0.1.0 lib/miam/password_manager.rb
miam-0.1.0.beta lib/miam/password_manager.rb