Class: Guac::Repo
- Inherits:
-
Object
- Object
- Guac::Repo
- Defined in:
- lib/guac/repo.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #branch ⇒ Object
- #checkout ⇒ Object
-
#initialize(config, repo, branch = nil) ⇒ Repo
constructor
A new instance of Repo.
- #pull ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(config, repo, branch = nil) ⇒ Repo
Returns a new instance of Repo.
13 14 15 16 17 18 19 |
# File 'lib/guac/repo.rb', line 13 def initialize(config, repo, branch = nil) @config = config @repo = repo @name = repo[:name] @dir = repo[:dir] @branch = branch || config[:default_branch] end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/guac/repo.rb', line 6 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/guac/repo.rb', line 6 def name @name end |
Class Method Details
.build_from_config(*args) ⇒ Object
8 9 10 11 |
# File 'lib/guac/repo.rb', line 8 def self.build_from_config(*args) config = Guac::Config.load config[:repos].map { |r| new(config, r, *args) } end |
.valid?(dirs) ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/guac/repo.rb', line 43 def self.valid?(dirs) !dirs.empty? && dirs.all? do |dir| d = File.join(dir.sub('~', ENV['HOME']), '.git') Dir.exist?(d) end end |
Instance Method Details
#branch ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/guac/repo.rb', line 21 def branch aliases = @repo[:branch_aliases] if aliases aliases[@branch] || @branch else @branch end end |
#checkout ⇒ Object
34 35 36 |
# File 'lib/guac/repo.rb', line 34 def checkout SysCommand.run(@dir, %W(git checkout #{branch})) end |
#pull ⇒ Object
38 39 40 41 |
# File 'lib/guac/repo.rb', line 38 def pull pull_cmd = @config[:pull_strategy].split(/ \s*/) SysCommand.run(@dir, pull_cmd) end |
#status ⇒ Object
30 31 32 |
# File 'lib/guac/repo.rb', line 30 def status SysCommand.run(@dir, %w(git status)) end |