Class: WorktreeManager::Worktree
- Inherits:
-
Object
- Object
- WorktreeManager::Worktree
- Defined in:
- lib/worktree_manager/worktree.rb
Instance Attribute Summary collapse
-
#bare ⇒ Object
readonly
Returns the value of attribute bare.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#detached ⇒ Object
readonly
Returns the value of attribute detached.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #bare? ⇒ Boolean
- #detached? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Worktree
constructor
A new instance of Worktree.
- #main? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
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
#bare ⇒ Object (readonly)
Returns the value of attribute bare.
3 4 5 |
# File 'lib/worktree_manager/worktree.rb', line 3 def @bare end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
3 4 5 |
# File 'lib/worktree_manager/worktree.rb', line 3 def branch @branch end |
#detached ⇒ Object (readonly)
Returns the value of attribute detached.
3 4 5 |
# File 'lib/worktree_manager/worktree.rb', line 3 def detached @detached end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
3 4 5 |
# File 'lib/worktree_manager/worktree.rb', line 3 def head @head end |
#path ⇒ Object (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
26 27 28 |
# File 'lib/worktree_manager/worktree.rb', line 26 def @bare end |
#detached? ⇒ Boolean
22 23 24 |
# File 'lib/worktree_manager/worktree.rb', line 22 def detached? @detached end |
#exists? ⇒ Boolean
34 35 36 |
# File 'lib/worktree_manager/worktree.rb', line 34 def exists? File.directory?(@path) end |
#main? ⇒ Boolean
30 31 32 |
# File 'lib/worktree_manager/worktree.rb', line 30 def main? @branch == 'main' || @branch == 'master' end |
#to_h ⇒ Object
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_s ⇒ Object
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 |