Class: Hiiro::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/hiiro/tasks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#branchObject (readonly)

Returns the value of attribute branch.



1420
1421
1422
# File 'lib/hiiro/tasks.rb', line 1420

def branch
  @branch
end

#headObject (readonly)

Returns the value of attribute head.



1420
1421
1422
# File 'lib/hiiro/tasks.rb', line 1420

def head
  @head
end

#pathObject (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.bare?
    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

Returns:

  • (Boolean)


1448
1449
1450
# File 'lib/hiiro/tasks.rb', line 1448

def detached?
  branch.nil?
end

#match?(pwd = Dir.pwd) ⇒ Boolean

Returns:

  • (Boolean)


1444
1445
1446
# File 'lib/hiiro/tasks.rb', line 1444

def match?(pwd = Dir.pwd)
  pwd == path || pwd.start_with?(path + '/')
end

#nameObject



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_sObject



1456
1457
1458
# File 'lib/hiiro/tasks.rb', line 1456

def to_s
  name
end