Class: Gitoc::Repository
- Inherits:
-
Object
- Object
- Gitoc::Repository
- Defined in:
- lib/gitoc/repository.rb
Class Attribute Summary collapse
-
.base ⇒ Object
Returns the value of attribute base.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Path to the git repository.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #clone ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(path, url = nil) ⇒ Repository
constructor
A new instance of Repository.
- #pull ⇒ Object
- #rel_path ⇒ Object
- #run_in(path, cmd) ⇒ Object
- #to_hash ⇒ Object
- #url ⇒ Object
- #url? ⇒ Boolean
Constructor Details
#initialize(path, url = nil) ⇒ Repository
Returns a new instance of Repository.
16 17 18 19 |
# File 'lib/gitoc/repository.rb', line 16 def initialize path, url = nil @path = Pathname.new(path). @url = url end |
Class Attribute Details
.base ⇒ Object
Returns the value of attribute base.
6 7 8 |
# File 'lib/gitoc/repository.rb', line 6 def base @base end |
Instance Attribute Details
#path ⇒ Object (readonly)
Path to the git repository
14 15 16 |
# File 'lib/gitoc/repository.rb', line 14 def path @path end |
Class Method Details
.load(attribute) ⇒ Object
8 9 10 |
# File 'lib/gitoc/repository.rb', line 8 def load attribute new base.join(attribute[:path]), attribute[:url] end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 |
# File 'lib/gitoc/repository.rb', line 21 def == other self.to_hash == other.to_hash end |
#clone ⇒ Object
51 52 53 54 55 |
# File 'lib/gitoc/repository.rb', line 51 def clone return unless url? path.parent.mkpath run_in path.parent, "git clone #{url}" end |
#exist? ⇒ Boolean
36 37 38 |
# File 'lib/gitoc/repository.rb', line 36 def exist? path.exist? end |
#pull ⇒ Object
57 58 59 60 |
# File 'lib/gitoc/repository.rb', line 57 def pull return unless exist? run_in path, "git pull" end |
#rel_path ⇒ Object
25 26 27 |
# File 'lib/gitoc/repository.rb', line 25 def rel_path @rel_path ||= path.relative_path_from(self.class.base) end |
#run_in(path, cmd) ⇒ Object
62 63 64 65 66 |
# File 'lib/gitoc/repository.rb', line 62 def run_in path, cmd Dir.chdir path do Open3.capture2 cmd end end |
#to_hash ⇒ Object
29 30 31 32 33 34 |
# File 'lib/gitoc/repository.rb', line 29 def to_hash { path: rel_path.to_s, url: url } end |
#url ⇒ Object
44 45 46 47 48 49 |
# 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? ⇒ Boolean
40 41 42 |
# File 'lib/gitoc/repository.rb', line 40 def url? !(url.nil? || url.empty?) end |