Class: Hiiro::Tree
- Inherits:
-
Object
- Object
- Hiiro::Tree
- Defined in:
- lib/hiiro/tasks.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #detached? ⇒ Boolean
-
#initialize(path:, head: nil, branch: nil) ⇒ Tree
constructor
A new instance of Tree.
- #match?(pwd = Dir.pwd) ⇒ Boolean
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path:, head: nil, branch: nil) ⇒ Tree
Returns a new instance of Tree.
1495 1496 1497 1498 1499 |
# File 'lib/hiiro/tasks.rb', line 1495 def initialize(path:, head: nil, branch: nil) @path = path @head = head @branch = branch end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
1478 1479 1480 |
# File 'lib/hiiro/tasks.rb', line 1478 def branch @branch end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
1478 1479 1480 |
# File 'lib/hiiro/tasks.rb', line 1478 def head @head end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
1478 1479 1480 |
# File 'lib/hiiro/tasks.rb', line 1478 def path @path end |
Class Method Details
.all(repo_path: Hiiro::REPO_PATH) ⇒ Object
1487 1488 1489 1490 1491 1492 1493 |
# File 'lib/hiiro/tasks.rb', line 1487 def self.all(repo_path: Hiiro::REPO_PATH) git = Hiiro::Git.new(nil, repo_path) git.worktrees(repo_path: repo_path).filter_map do |wt| next if wt. new(path: wt.path, head: wt.head, branch: wt.branch) end end |
Instance Method Details
#==(other) ⇒ Object
1517 1518 1519 |
# File 'lib/hiiro/tasks.rb', line 1517 def ==(other) other.is_a?(Tree) && path == other.path end |
#detached? ⇒ Boolean
1513 1514 1515 |
# File 'lib/hiiro/tasks.rb', line 1513 def detached? branch.nil? end |
#match?(pwd = Dir.pwd) ⇒ Boolean
1509 1510 1511 |
# File 'lib/hiiro/tasks.rb', line 1509 def match?(pwd = Dir.pwd) pwd == path || pwd.start_with?(path + '/') end |
#name ⇒ Object
1501 1502 1503 1504 1505 1506 1507 |
# File 'lib/hiiro/tasks.rb', line 1501 def name @name ||= if path.start_with?(Hiiro::WORK_DIR + '/') path.sub(Hiiro::WORK_DIR + '/', '') else File.basename(path) end end |
#to_s ⇒ Object
1521 1522 1523 |
# File 'lib/hiiro/tasks.rb', line 1521 def to_s name end |