Sha256: f94a914465d7e0f72a3efbfcceab48fd544d5ade6ff0edb9ec0bd2a0c597773f

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 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
                return nil
            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

8 entries across 8 versions & 1 rubygems

Version Path
build-tool-0.5.7 lib/build-tool/repository.rb
build-tool-0.5.6 lib/build-tool/repository.rb
build-tool-0.5.5 lib/build-tool/repository.rb
build-tool-0.5.4 lib/build-tool/repository.rb
build-tool-0.5.3 lib/build-tool/repository.rb
build-tool-0.5.2 lib/build-tool/repository.rb
build-tool-0.5.1 lib/build-tool/repository.rb
build-tool-0.5.0 lib/build-tool/repository.rb