Class: BuildTool::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/build-tool/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, theurl = nil) ⇒ Server

Create a repository



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/build-tool/server.rb', line 25

def initialize( name, theurl = nil )
    @host = nil
    @name = nil
    @path = nil
    @protocol = nil
    @sshkey = nil
    if name.nil?
        raise StandardError, "The server name has to be set"
    end
    @name = name
    if theurl
        uri = URI.parse( theurl )
        @host = uri.host
        @protocol = uri.scheme
        if not uri.path.empty?
            @path = uri.path
        end
    end
end

Instance Attribute Details

#hostObject

The host this repository is hosted



10
11
12
# File 'lib/build-tool/server.rb', line 10

def host
  @host
end

#nameObject (readonly)

Repository name



13
14
15
# File 'lib/build-tool/server.rb', line 13

def name
  @name
end

#pathObject

The relative path on the server



16
17
18
# File 'lib/build-tool/server.rb', line 16

def path
  @path
end

#protocolObject

The protocol used to access the repository



19
20
21
# File 'lib/build-tool/server.rb', line 19

def protocol
  @protocol
end

#sshkeyObject

A ssh key associated with this server



22
23
24
# File 'lib/build-tool/server.rb', line 22

def sshkey
  @sshkey
end

Instance Method Details

#to_sObject



67
68
69
# File 'lib/build-tool/server.rb', line 67

def to_s
    "Server: #{url}"
end

#url(user = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/build-tool/server.rb', line 45

def url( user = nil )
    if !host
        raise ConfigurationError, "No host specified for server #{name}"
    end

    url = host
    if user
        url = "#{user}@#{url}"
    end
    if protocol
        url = "#{protocol}://#{url}"
    end
    if path
        if path[0] == '/'
            url = "#{url}#{path}"
        else
            url = "#{url}/#{path}"
        end
    end
    url
end