Sha256: 8c656d210d6abf25328cfd91e0d7f380fa3168b403e556d16003d6a37a62d594

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require 'pullr/scm/scm'

require 'addressable/uri'

module Pullr
  module Repository
    #
    # Initializes the repository.
    #
    # @param [Hash] options
    #   Options for 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={})
      @scm = options[:scm]
      @uri = nil

      case options[:uri]
      when Addressable::URI
        @uri = options[:uri]
      when Hash
        @uri = Addressable::URI.new(options[:uri])
      when URI::Generic, String
        @uri = Addressable::URI.parse(options[:uri])
      end
    end

    protected

    #
    # Attempts to infer the SCM used for the remote repository.
    #
    # @return [Boolean]
    #   Specifies whether the SCM was infered from the repository's URI.
    #
    def infer_scm_from_uri
      if @uri
        if (@scm = SCM.infer_from_uri(@uri))
          return true
        end
      end

      return false
    end

    #
    # Attempts to infer the SCM used for the repository.
    #
    # @return [Boolean]
    #   Specifies whether the SCM was successfully infered.
    #
    def infer_scm_from_dir
      if @path
        if (@scm = SCM.infer_from_dir(@path))
          return true
        end
      end

      return false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pullr-0.1.2 lib/pullr/repository.rb
pullr-0.1.1 lib/pullr/repository.rb