Class: Giturl::Location
- Inherits:
-
Data
- Object
- Data
- Giturl::Location
- 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
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Whether git answered with everything a URL needs.
-
#encoded_branch ⇒ String
The branch in the form a URL path can carry, each segment percent-encoded but the separating slashes left intact.
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch
9 10 11 |
# File 'lib/giturl/location.rb', line 9 def branch @branch end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix
9 10 11 |
# File 'lib/giturl/location.rb', line 9 def prefix @prefix end |
#remote ⇒ Object (readonly)
Returns the value of attribute 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.
12 13 14 |
# File 'lib/giturl/location.rb', line 12 def complete? !branch.empty? && !remote.empty? end |
#encoded_branch ⇒ String
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 |