Sha256: 696128bda5ea58e203d1af22d1dce6ce2c72138acfb0b00e9f1d653830dd1ecf

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 KB

Contents

# -*- coding: UTF-8 -*-

require 'uri'

module BuildTool

    class Server

        # The host this repository is hosted
        attr_accessor :host

        # Repository name
        attr_reader   :name

        # The relative path on the server
        attr_accessor :path

        # The protocol used to access the repository
        attr_accessor :protocol

        # A ssh key associated with this server
        attr_accessor :sshkey

        # Create a repository
        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

        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

        def to_s
            "Server: #{url}"
        end

    end # class Server


end # module BuildTool

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
build-tool-0.6.9 lib/build-tool/server.rb
build-tool-0.6.8 lib/build-tool/server.rb
build-tool-0.6.7 lib/build-tool/server.rb
build-tool-0.6.6 lib/build-tool/server.rb
build-tool-0.6.5 lib/build-tool/server.rb
build-tool-0.6.4 lib/build-tool/server.rb
build-tool-0.6.3 lib/build-tool/server.rb
build-tool-0.6.2 lib/build-tool/server.rb
build-tool-0.6.1 lib/build-tool/server.rb
build-tool-0.6.0 lib/build-tool/server.rb
build-tool-0.6.0.rc2 lib/build-tool/server.rb
build-tool-0.6.0.rc1 lib/build-tool/server.rb