Class: Carson::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, runtime:) ⇒ Repository

Returns a new instance of Repository.



6
7
8
9
# File 'lib/carson/repository.rb', line 6

def initialize( path:, runtime: )
	@path = File.expand_path( path )
	@runtime = runtime
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#branch(name) ⇒ Object

Returns a passive branch record for the given branch name.



17
18
19
# File 'lib/carson/repository.rb', line 17

def branch( name )
	Branch.new( repository: self, name: name, runtime: runtime )
end

#branchesObject

Lists local branches as passive branch records.



22
23
24
25
26
27
28
29
30
# File 'lib/carson/repository.rb', line 22

def branches
	runtime.git_capture!( "for-each-ref", "--format=%(refname:short)", "refs/heads" )
		.lines
		.map( &:strip )
		.reject( &:empty? )
		.map { |branch_name| branch( branch_name ) }
rescue StandardError
	[]
end

#nameObject

Human-readable repository name derived from the filesystem path.



12
13
14
# File 'lib/carson/repository.rb', line 12

def name
	File.basename( path )
end

#statusObject

Reports the repository’s delivery-centred state for status surfaces.



33
34
35
36
37
38
39
# File 'lib/carson/repository.rb', line 33

def status
	{
		name: name,
		path: path,
		branches: runtime.ledger.active_deliveries( repo_path: path ).map { |delivery| delivery.branch }
	}
end