Sha256: 6fb1d0f0b9b8b3291afb54b48a49280f94844d75a6692c8c8b5f20aa18d8be73

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require 'pullr/exceptions/ambigious_repository'
require 'pullr/repository'

module Pullr
  class LocalRepository

    include Repository

    # The path of the repository
    attr_reader :path

    # The SCM used for the repository
    attr_reader :scm

    # Optional URI for the remote repository
    attr_accessor :uri

    #
    # Initializes the repository.
    #
    # @param [Hash] options
    #   Options for the repository.
    #
    # @option options [String] :path
    #   Path to the repository.
    #
    # @option options [Symbol, String] :scm
    #   The SCM used to manage the repository.
    #
    # @option options [URI::Generic] :uri
    #   Optional URI for the remote repository.
    #
    def initialize(options={})
      super(options)

      @path = options[:path]

      unless @scm
        infer_scm_from_dir && infer_scm_from_uri
      end

      unless @scm
        raise(AmbigiousRepository,"could not infer the SCM from the directory #{@path.dump}",caller)
      end

      extend SCM.lookup(@scm)
    end

    #
    # The name of the repository.
    #
    # @return [String]
    #   The local repository name.
    #
    # @since 0.1.2
    #
    def name
      File.basename(@path)
    end

    #
    # The control directory used by the SCM.
    #
    # @return [String]
    #   The name of the control directory.
    #
    def scm_dir
      dir, scm = SCM::DIRS.find { |dir,scm| scm == @scm }

      return dir
    end

    #
    # Pulls any new updates for the repository down.
    #
    # @param [URI::Generic] uri
    #   Optional URI to pull from.
    #
    def update(uri=self.uri)
      scm_update(@path,uri)
    end
  
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pullr-0.1.3 lib/pullr/local_repository.rb
pullr-0.1.2 lib/pullr/local_repository.rb