Class: Git::Worktrees

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/git/worktrees.rb

Overview

object that holds all the available worktrees

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Worktrees

Returns a new instance of Worktrees.



7
8
9
10
11
12
13
14
15
16
# File 'lib/git/worktrees.rb', line 7

def initialize(base)
  @worktrees = {}

  @base = base

  # Array contains [dir, git_hash]
  @base.lib.worktrees_all.each do |w|
    @worktrees[w[0]] = Git::Worktree.new(@base, w[0], w[1])
  end
end

Instance Method Details

#[](worktree_name) ⇒ Object



28
29
30
31
32
33
# File 'lib/git/worktrees.rb', line 28

def [](worktree_name)
  @worktrees.values.inject(@worktrees) do |worktrees, worktree|
    worktrees[worktree.full] ||= worktree
    worktrees
  end[worktree_name.to_s]
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/git/worktrees.rb', line 24

def each(&block)
  @worktrees.values.each(&block)
end

#pruneObject



43
44
45
# File 'lib/git/worktrees.rb', line 43

def prune
  @base.lib.worktree_prune
end

#sizeObject

array like methods



20
21
22
# File 'lib/git/worktrees.rb', line 20

def size
  @worktrees.size
end

#to_sObject



35
36
37
38
39
40
41
# File 'lib/git/worktrees.rb', line 35

def to_s
  out = ''
  @worktrees.each do |k, b|
    out << b.to_s << "\n"
  end
  out
end