Class: Swat::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/swat_git.rb

Overview

Git handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = ENV["SCRIPTS_REMOTE_URL"], target = ENV["SCRIPTS_LOCAL_PATH"]) ⇒ Git

Returns a new instance of Git.



10
11
12
13
# File 'lib/swat_git.rb', line 10

def initialize(source = ENV["SCRIPTS_REMOTE_URL"], target = ENV["SCRIPTS_LOCAL_PATH"])
  @source = source
  @target = target
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



8
9
10
# File 'lib/swat_git.rb', line 8

def source
  @source
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/swat_git.rb', line 8

def target
  @target
end

Instance Method Details

#updateObject



19
20
21
22
23
24
25
# File 'lib/swat_git.rb', line 19

def update
  if Dir.exist?(@target)
    pull
  else
    clone
  end
end

#valid?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/swat_git.rb', line 27

def valid?
  return false unless File.exist?(@target)
  Dir.chdir(@target) {
    `git config --get remote.origin.url`.strip == @source
  }
end

#wipeObject



15
16
17
# File 'lib/swat_git.rb', line 15

def wipe
  FileUtils.rm_rf(@target) if File.writable?(@target)
end