Sha256: c8079af7b95076e7bde602539cb3dc28097fd58350ffe96b299c1b61004e0157

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

module CukeQ
  class Scm
    attr_reader :url

    autoload :GitBridge, "cukeq/scm/git_bridge"
    autoload :SvnBridge, "cukeq/scm/svn_bridge"

    def initialize(url, root_dir = CukeQ.root)
      @root_dir = root_dir
      @url = url.kind_of?(String) ? URI.parse(url) : url
    end

    def working_copy
      @working_copy ||= "#{@root_dir}/repos/#{url.host}/#{url.path.gsub(/[^A-z]+/, '_')}"
    end

    def current_revision
      bridge.current_revision
    end

    def update(&blk)
      log self.class, :updating, url.to_s => working_copy
      bridge.update(&blk)
      log self.class, :done
    end

    def bridge
      @bridge ||= (
        case url.scheme
        when "git"
          GitBridge.new url, working_copy
        when "svn"
          SvnBridge.new url, working_copy
        when "http", "https"
          # TODO: fix heuristic for http scm urls
          if url.to_s.include?("svn")
            SvnBridge.new url, working_copy
          elsif url.to_s.include?("git")
            GitBridge.new url, working_copy
          else
            raise "unknown scm: #{url}"
          end
        else
          raise "unknown scm: #{url}"
        end
      )
    end

  end # Scm
end # CukeQ

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cukeq-0.0.1.dev5 lib/cukeq/scm.rb
cukeq-0.0.1.dev4 lib/cukeq/scm.rb
cukeq-0.0.1.dev3 lib/cukeq/scm.rb
cukeq-0.0.1.dev2 lib/cukeq/scm.rb