Sha256: 2596812fb5f997320180a32751ad83aeed3d22bafaf76e072d3e8f02e19fd93a

Contents?: true

Size: 986 Bytes

Versions: 2

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true
require 'shellwords'

# ProxyRb
module ProxyRb
  # Hold proxy credentials
  class Credentials
    attr_reader :user_name, :password

    # @param [String] user_name
    #   The user name to use for authentication against proxy
    #
    # @param [String] password
    #   The password to use for authentication against proxy
    def initialize(user_name, password)
      @user_name = user_name
      @password  = password
    end

    # Convert to string
    #
    # @return [String]
    #   A formatted string <user>:<password>
    def to_s
      Shellwords.escape(format('%s:%s', user_name, password))
    end

    # Is credentials empty
    #
    # @return [TrueClass, FalseClass]
    #   Empty if any user_name or password is empty
    def empty?
      !(user_name? && password?)
    end

    private

    def user_name?
      !(user_name.nil? || user_name.empty?)
    end

    def password?
      !(password.nil? || password.empty?)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxy_rb-0.4.0 lib/proxy_rb/credentials.rb
proxy_rb-0.3.0 lib/proxy_rb/credentials.rb