Class: ProxyRb::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_rb/credentials.rb

Overview

Hold proxy credentials

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_name, password) ⇒ Credentials

Returns a new instance of Credentials.

Parameters:

  • user_name (String) —

    The user name to use for authentication against proxy

  • password (String) —

    The password to use for authentication against proxy



15
16
17
18
# File 'lib/proxy_rb/credentials.rb', line 15

def initialize(user_name, password)
  @user_name = user_name
  @password  = password
end

Instance Attribute Details

#password ⇒ Object (readonly)

Returns the value of attribute password.



8
9
10
# File 'lib/proxy_rb/credentials.rb', line 8

def password
  @password
end

#user_name ⇒ Object (readonly)

Returns the value of attribute user_name.



8
9
10
# File 'lib/proxy_rb/credentials.rb', line 8

def user_name
  @user_name
end

Instance Method Details

#empty? ⇒ TrueClass, FalseClass

Is credentials empty

Returns:

  • (TrueClass, FalseClass) —

    Empty if any user_name or password is empty



32
33
34
# File 'lib/proxy_rb/credentials.rb', line 32

def empty?
  !(user_name? && password?)
end

#to_hash ⇒ Hash

Convert to hash

Returns:

  • (Hash) —

    The credentials as hash



40
41
42
43
44
45
# File 'lib/proxy_rb/credentials.rb', line 40

def to_hash
  {
    user_name: user_name,
    password: password
  }
end

#to_s ⇒ String

Convert to string

Returns:

  • (String) —

    A formatted string :



24
25
26
# File 'lib/proxy_rb/credentials.rb', line 24

def to_s
  Shellwords.escape(format('%s:%s', user_name, password))
end