Class: Guac::Repo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/guac/repo.rb', line 6

def dir
  @dir
end

#nameObject (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

Returns:

  • (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

#branchObject



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

#checkoutObject



34
35
36
# File 'lib/guac/repo.rb', line 34

def checkout
  SysCommand.run(@dir, %W(git checkout #{branch}))
end

#pullObject



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

#statusObject



30
31
32
# File 'lib/guac/repo.rb', line 30

def status
  SysCommand.run(@dir, %w(git status))
end