Class: Swat::Git
- Inherits:
-
Object
- Object
- Swat::Git
- Defined in:
- lib/swat_git.rb
Overview
Git handler
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(source = ENV["SCRIPTS_REMOTE_URL"], target = ENV["SCRIPTS_LOCAL_PATH"]) ⇒ Git
constructor
A new instance of Git.
- #update ⇒ Object
- #valid? ⇒ Boolean
- #wipe ⇒ Object
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
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/swat_git.rb', line 8 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/swat_git.rb', line 8 def target @target end |
Instance Method Details
#update ⇒ Object
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
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 |
#wipe ⇒ Object
15 16 17 |
# File 'lib/swat_git.rb', line 15 def wipe FileUtils.rm_rf(@target) if File.writable?(@target) end |