Class: LgPodPlugin::LURI

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/net/l_uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git) ⇒ LURI

Returns a new instance of LURI.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 16

def initialize(git)
  begin
    uri = URI(git)
  rescue => exception
    if git.include?("git@") && git.include?(":")
      match = %r{(?<=git@).*?(?=:)}.match(git)
      host = match ? match[0] : ""
      base_url = LUtils.get_gitlab_base_url(git)
      path = base_url.split(":").last
      uri = URI("http://#{host}/#{path}")
    else
      LgPodPlugin.log_red exception
      uri = nil
    end
  end
  return unless uri
  ip_address = getaddress(uri)
  return unless ip_address
  if git.include?("ssh") || git.include?("git@gitlab") || git.include?("git@")
    @uri = URI("http://#{ip_address}#{uri.path}")
  else
    @uri = URI("#{uri.scheme}://#{ip_address}#{uri.path}")
  end
  @ip = ip_address
  @host = @uri.host ||= ""
  @path = @uri.path ||= ""
  @scheme = @uri.scheme ||= ""
  @hostname =  @scheme + "://" + @host
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 10

def host
  @host
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



12
13
14
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 12

def hostname
  @hostname
end

#ipObject (readonly)

Returns the value of attribute ip.



8
9
10
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 8

def ip
  @ip
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 9

def path
  @path
end

#schemeObject (readonly)

Returns the value of attribute scheme.



11
12
13
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 11

def scheme
  @scheme
end

Instance Method Details

#to_sObject



79
80
81
82
# File 'lib/lg_pod_plugin/net/l_uri.rb', line 79

public def to_s
  return "" unless @uri
  @uri.to_s
end