Class: Giturl::Location

Inherits:
Data
  • Object
show all
Defined in:
lib/giturl/location.rb

Overview

Where a directory sits inside its repository: the path from the repository root down to it, the branch checked out, and the URL of the remote it came from. Immutable; built by GitDirectory from what git reports.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch

Returns:

  • the current value of branch



9
10
11
# File 'lib/giturl/location.rb', line 9

def branch
  @branch
end

#prefixObject (readonly)

Returns the value of attribute prefix

Returns:

  • the current value of prefix



9
10
11
# File 'lib/giturl/location.rb', line 9

def prefix
  @prefix
end

#remoteObject (readonly)

Returns the value of attribute remote

Returns:

  • the current value of remote



9
10
11
# File 'lib/giturl/location.rb', line 9

def remote
  @remote
end

Instance Method Details

#complete?Boolean

Returns whether git answered with everything a URL needs. prefix is legitimately empty at the repository root, so it is not required.

Returns:

  • whether git answered with everything a URL needs. prefix is legitimately empty at the repository root, so it is not required.



12
13
14
# File 'lib/giturl/location.rb', line 12

def complete?
  !branch.empty? && !remote.empty?
end

#encoded_branchString

Returns the branch in the form a URL path can carry, each segment percent-encoded but the separating slashes left intact.

Returns:

  • the branch in the form a URL path can carry, each segment percent-encoded but the separating slashes left intact



18
19
20
# File 'lib/giturl/location.rb', line 18

def encoded_branch
  branch.split('/').map { |segment| ERB::Util.url_encode(segment) }.join('/')
end