Sha256: 2c19fb36aee3af7094d9c3ba6dcfc0b4ee1381d43692613545002b6f907634b6

Contents?: true

Size: 741 Bytes

Versions: 4

Compression:

Stored size: 741 Bytes

Contents

# frozen_string_literal: true

module Jive
  class Git
    attr_reader :shell

    def initialize(shell)
      @shell = shell
    end

    def clone(slug)
      dir = target_dir_for(slug)
      unless dir.exist?
        shell.run_each([
          [:mkdir, "-p", dir.parent.to_s],
          [:git, "clone", "git@github.com:#{slug}.git", dir]
        ])
      end
      cd(slug)
    end

    def cd(slug)
      dir = target_dir_for(slug)
      if dir.exist?
        shell.after_run([
          ["cd", dir],
          ["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
        ])
      else
        clone(slug)
      end
    end

    private

    def target_dir_for(slug)
      Pathname.new(Dir.home).join("src/github.com/#{slug}")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jive-0.3.1 lib/jive/git.rb
jive-0.3.0 lib/jive/git.rb
jive-0.2.3 lib/jive/git.rb
jive-0.2.2 lib/jive/git.rb