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.
1430 1431 1432 1433 1434 |
# File 'lib/hiiro/tasks.rb', line 1430 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.
1420 1421 1422 |
# File 'lib/hiiro/tasks.rb', line 1420 def branch @branch end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
1420 1421 1422 |
# File 'lib/hiiro/tasks.rb', line 1420 def head @head end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
1420 1421 1422 |
# File 'lib/hiiro/tasks.rb', line 1420 def path @path end |
Class Method Details
.all(repo_path: Hiiro::REPO_PATH) ⇒ Object
1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/hiiro/tasks.rb', line 1422 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
1452 1453 1454 |
# File 'lib/hiiro/tasks.rb', line 1452 def ==(other) other.is_a?(Tree) && path == other.path end |
#detached? ⇒ Boolean
1448 1449 1450 |
# File 'lib/hiiro/tasks.rb', line 1448 def detached? branch.nil? end |
#match?(pwd = Dir.pwd) ⇒ Boolean
1444 1445 1446 |
# File 'lib/hiiro/tasks.rb', line 1444 def match?(pwd = Dir.pwd) pwd == path || pwd.start_with?(path + '/') end |
#name ⇒ Object
1436 1437 1438 1439 1440 1441 1442 |
# File 'lib/hiiro/tasks.rb', line 1436 def name @name ||= if path.start_with?(Hiiro::WORK_DIR + '/') path.sub(Hiiro::WORK_DIR + '/', '') else File.basename(path) end end |
#to_s ⇒ Object
1456 1457 1458 |
# File 'lib/hiiro/tasks.rb', line 1456 def to_s name end |