Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-http-basic-authentication.rb

Instance Method Summary collapse

Instance Method Details

#with_basic_authenticationObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-http-basic-authentication.rb', line 15

def with_basic_authentication
  self.define_singleton_method(:to_s) do
    u = self.split("://")
    $stdout.puts "#{self} needs authentication"
    $stdout.print "login: "
    user = $stdin.gets.chomp
    $stdout.print "password: "
    password = $stdin.noecho(&:gets).chomp
    "#{u[0]}://#{user}:#{password}@#{u[1]}"
  end
  self
end