Class: UnixCrypt::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/unix_crypt/command_line.rb

Defined Under Namespace

Classes: Opts

Constant Summary collapse

Abort =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CommandLine

Returns a new instance of CommandLine.



15
16
17
# File 'lib/unix_crypt/command_line.rb', line 15

def initialize(argv)
  @options = Opts.parse(argv)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/unix_crypt/command_line.rb', line 13

def options
  @options
end

Instance Method Details

#encryptObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/unix_crypt/command_line.rb', line 19

def encrypt
  if @options.password.nil?
    @options.password = ask_password
  else
    password_warning
  end

  begin
    puts @options.hasher.build(@options.password, @options.salt, @options.rounds)
  rescue UnixCrypt::Error => e
    $stderr.puts "password generation failed: #{e.message}"
  end

  clear_string(@options.password)
end