class Gitoc::Repository
Attributes
base[RW]
path[R]
Path to the git repository
Public Class Methods
load(attribute)
click to toggle source
# File lib/gitoc/repository.rb, line 8 def load attribute new base.join(attribute[:path]), attribute[:url] end
new(path, url = nil)
click to toggle source
# File lib/gitoc/repository.rb, line 16 def initialize path, url = nil @path = Pathname.new(path).expand_path @url = url end
Public Instance Methods
==(other)
click to toggle source
# File lib/gitoc/repository.rb, line 21 def == other self.to_hash == other.to_hash end
clone()
click to toggle source
# File lib/gitoc/repository.rb, line 51 def clone return unless url? path.parent.mkpath run_in path.parent, "git clone #{url}" end
exist?()
click to toggle source
# File lib/gitoc/repository.rb, line 36 def exist? path.exist? end
pull()
click to toggle source
# File lib/gitoc/repository.rb, line 57 def pull return unless exist? run_in path, "git pull" end
rel_path()
click to toggle source
# File lib/gitoc/repository.rb, line 25 def rel_path @rel_path ||= path.relative_path_from(self.class.base) end
run_in(path, cmd)
click to toggle source
# File lib/gitoc/repository.rb, line 62 def run_in path, cmd Dir.chdir path do Open3.capture2 cmd end end
to_hash()
click to toggle source
# File lib/gitoc/repository.rb, line 29 def to_hash { path: rel_path.to_s, url: url } end
url()
click to toggle source
# File lib/gitoc/repository.rb, line 44 def url @url ||= begin out, _status = run_in path, "git config remote.origin.url" out.chomp end end
url?()
click to toggle source
# File lib/gitoc/repository.rb, line 40 def url? !(url.nil? || url.empty?) end