Class: Pact::Provider::PactURI

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/provider/pact_uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = nil, metadata = nil) ⇒ PactURI

Returns a new instance of PactURI.



6
7
8
9
10
# File 'lib/pact/provider/pact_uri.rb', line 6

def initialize(uri, options = nil,  = nil)
  @uri = uri
  @options = options || {}
  @metadata =  || {} # make sure it's not nil if nil is passed in
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



4
5
6
# File 'lib/pact/provider/pact_uri.rb', line 4

def 
  @metadata
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/pact/provider/pact_uri.rb', line 4

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



4
5
6
# File 'lib/pact/provider/pact_uri.rb', line 4

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
# File 'lib/pact/provider/pact_uri.rb', line 12

def == other
  other.is_a?(PactURI) &&
    uri == other.uri &&
    options == other.options &&
     == other.
end

#basic_auth?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pact/provider/pact_uri.rb', line 19

def basic_auth?
  !!username && !!password
end

#passwordObject



27
28
29
# File 'lib/pact/provider/pact_uri.rb', line 27

def password
  options[:password]
end

#to_sObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pact/provider/pact_uri.rb', line 31

def to_s
  if basic_auth? && http_or_https_uri?
    begin
      URI(@uri).tap { |x| x.userinfo="#{username}:*****"}.to_s
    rescue URI::InvalidComponentError
      URI(@uri).tap { |x| x.userinfo="*****:*****"}.to_s
    end
  elsif personal_access_token? && http_or_https_uri?
    URI(@uri).tap { |x| x.userinfo="*****"}.to_s
  else
    uri
  end
end

#usernameObject



23
24
25
# File 'lib/pact/provider/pact_uri.rb', line 23

def username
  options[:username]
end