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:, authority:, runtime:) ⇒ Repository

Returns a new instance of Repository.



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

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

Instance Attribute Details

#authorityObject (readonly)

Returns the value of attribute authority.



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

def authority
  @authority
end

#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.



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

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

#branchesObject

Lists local branches as passive branch records.



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

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.



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

def name
	File.basename( path )
end

#statusObject

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



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

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