Class: Carson::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/carson/branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository:, name:, runtime:, purpose: nil, head: nil, worktree: nil, delivery: nil) ⇒ Branch

Returns a new instance of Branch.



6
7
8
9
10
11
12
13
14
# File 'lib/carson/branch.rb', line 6

def initialize( repository:, name:, runtime:, purpose: nil, head: nil, worktree: nil, delivery: nil )
	@repository = repository
	@name = name
	@runtime = runtime
	@purpose = purpose
	@head = head
	@worktree = worktree
	@delivery = delivery
end

Instance Attribute Details

#deliveryObject (readonly)

Returns the value of attribute delivery.



4
5
6
# File 'lib/carson/branch.rb', line 4

def delivery
  @delivery
end

#headObject (readonly)

Returns the value of attribute head.



4
5
6
# File 'lib/carson/branch.rb', line 4

def head
  @head
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/carson/branch.rb', line 4

def name
  @name
end

#purposeObject (readonly)

Returns the value of attribute purpose.



4
5
6
# File 'lib/carson/branch.rb', line 4

def purpose
  @purpose
end

#repositoryObject (readonly)

Returns the value of attribute repository.



4
5
6
# File 'lib/carson/branch.rb', line 4

def repository
  @repository
end

#worktreeObject (readonly)

Returns the value of attribute worktree.



4
5
6
# File 'lib/carson/branch.rb', line 4

def worktree
  @worktree
end

Instance Method Details

#reloadObject

Re-reads the branch facts from git and Carson’s ledger.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/carson/branch.rb', line 17

def reload
	refreshed_head = runtime.git_capture!( "rev-parse", name ).strip
	refreshed_worktree = runtime.worktree_list.find { |entry| entry.branch == name }&.path || worktree
	refreshed_delivery = runtime.ledger.active_delivery( repo_path: repository.path, branch_name: name )
	self.class.new(
		repository: repository,
		name: name,
		runtime: runtime,
		purpose: purpose,
		head: refreshed_head,
		worktree: refreshed_worktree,
		delivery: refreshed_delivery
	)
rescue StandardError
	self
end