Class: Gitlab::Git::Ref
- Inherits:
-
Object
- Object
- Gitlab::Git::Ref
- Includes:
- EncodingHelper
- Defined in:
- lib/gitlab_git/ref.rb
Constant Summary
Constants included from EncodingHelper
EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD
Instance Attribute Summary collapse
-
#dereferenced_target ⇒ Object
readonly
Dereferenced target Commit object to which the Ref points to.
-
#name ⇒ Object
readonly
Branch or tag name without “refs/tags|heads” prefix.
-
#target ⇒ Object
readonly
Target sha.
Class Method Summary collapse
- .dereference_object(object) ⇒ Object
-
.extract_branch_name(str) ⇒ Object
Extract branch name from full ref path.
Instance Method Summary collapse
-
#initialize(repository, name, target) ⇒ Ref
constructor
A new instance of Ref.
Methods included from EncodingHelper
Constructor Details
#initialize(repository, name, target) ⇒ Ref
Returns a new instance of Ref.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab_git/ref.rb', line 33 def initialize(repository, name, target) encode! name @name = name.gsub(/\Arefs\/(tags|heads)\//, '') @dereferenced_target = Commit.find(repository, target) @target = if target.respond_to?(:oid) target.oid elsif target.respond_to?(:name) target.name elsif target.is_a? String target else nil end end |
Instance Attribute Details
#dereferenced_target ⇒ Object (readonly)
Dereferenced target Commit object to which the Ref points to
17 18 19 |
# File 'lib/gitlab_git/ref.rb', line 17 def dereferenced_target @dereferenced_target end |
#name ⇒ Object (readonly)
Branch or tag name without “refs/tags|heads” prefix
8 9 10 |
# File 'lib/gitlab_git/ref.rb', line 8 def name @name end |
#target ⇒ Object (readonly)
Target sha. Usually it is commit sha but in case when tag reference on other tag it can be tag sha
13 14 15 |
# File 'lib/gitlab_git/ref.rb', line 13 def target @target end |
Class Method Details
.dereference_object(object) ⇒ Object
27 28 29 30 31 |
# File 'lib/gitlab_git/ref.rb', line 27 def self.dereference_object(object) object = object.target while object.is_a?(Rugged::Tag::Annotation) object end |
.extract_branch_name(str) ⇒ Object
Extract branch name from full ref path
Ex.
Ref.extract_branch_name('refs/heads/master') #=> 'master'
23 24 25 |
# File 'lib/gitlab_git/ref.rb', line 23 def self.extract_branch_name(str) str.gsub(/\Arefs\/heads\//, '') end |