Class: WorktreeManager::Worktree

Inherits:
Object
  • Object
show all
Defined in:
lib/worktree_manager/worktree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Worktree

Returns a new instance of Worktree.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/worktree_manager/worktree.rb', line 5

def initialize(attributes = {})
  case attributes
  when Hash
    @path = attributes[:path]
    @branch = attributes[:branch]
    @head = attributes[:head]
    @detached = attributes[:detached] || false
    @bare = attributes[:bare] || false
  when String
    @path = attributes
    @branch = nil
    @head = nil
    @detached = false
    @bare = false
  end
end

Instance Attribute Details

#bareObject (readonly)

Returns the value of attribute bare.



3
4
5
# File 'lib/worktree_manager/worktree.rb', line 3

def bare
  @bare
end

#branchObject (readonly)

Returns the value of attribute branch.



3
4
5
# File 'lib/worktree_manager/worktree.rb', line 3

def branch
  @branch
end

#detachedObject (readonly)

Returns the value of attribute detached.



3
4
5
# File 'lib/worktree_manager/worktree.rb', line 3

def detached
  @detached
end

#headObject (readonly)

Returns the value of attribute head.



3
4
5
# File 'lib/worktree_manager/worktree.rb', line 3

def head
  @head
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/worktree_manager/worktree.rb', line 3

def path
  @path
end

Instance Method Details

#bare?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/worktree_manager/worktree.rb', line 26

def bare?
  @bare
end

#detached?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/worktree_manager/worktree.rb', line 22

def detached?
  @detached
end

#exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/worktree_manager/worktree.rb', line 34

def exists?
  File.directory?(@path)
end

#main?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/worktree_manager/worktree.rb', line 30

def main?
  @branch == 'main' || @branch == 'master'
end

#to_hObject



46
47
48
49
50
51
52
53
54
# File 'lib/worktree_manager/worktree.rb', line 46

def to_h
  {
    path: @path,
    branch: @branch,
    head: @head,
    detached: @detached,
    bare: @bare
  }
end

#to_sObject



38
39
40
41
42
43
44
# File 'lib/worktree_manager/worktree.rb', line 38

def to_s
  if @branch
    "#{@path} (#{@branch})"
  else
    "#{@path} (#{@head})"
  end
end