Sha256: 6d17b191347bf4b1ea3913e37f44bbd268feed69d81b164ff2eb8aa740281c91

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

require 'build-tool/errors'

module BuildTool

    # Encapsulates a source code repository.
    class Repository

        # Repository name
        attr_reader   :name

        # The server this repository is hosted
        attr_accessor :server

        # The relative path on the server
        attr_accessor :path

        # The relative path on the server
        attr_accessor :user

        # The associated ssh-key
        attr_writer :sshkey

        # Create a repository
        def initialize(name)
            if name.nil?
                raise StandardError, "The repository name has to be set"
            end
            @name = name
            @server = nil
            @sshkey = nil
        end

        # Return the ssh key needed to access this repository. If the repository has no key we
        # check the associated server.
        def sshkey
            return @sshkey if @sshkey

            if !server
                raise ConfigurationError, "No server specified for repository #{name}"
            end

            return server.sshkey
        end

        def url
            if !server
                raise ConfigurationError, "No server specified for repository #{name}"
            end
            if !server.host
                raise ConfigurationError, "No host specified for server #{server.name}"
            end

            url = server.host
            if server.path
                url = "#{url}/#{server.path}"
            end
            if user
                url = "#{user}@#{url}"
            end
            if server.protocol
                url = "#{server.protocol}://#{url}"
            end
            if path
                url = "#{url}/#{path}"
            end
            url
        end

    end # class Repository

end # module BuildTool

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
build-tool-0.4.6 lib/build-tool/repository.rb
build-tool-0.4.5 lib/build-tool/repository.rb
build-tool-0.4.4 lib/build-tool/repository.rb
build-tool-0.4.3 lib/build-tool/repository.rb
build-tool-0.4.2 lib/build-tool/repository.rb