Class: Grit::Tag

Inherits:
Ref
  • Object
show all
Defined in:
lib/grit/ref.rb,
lib/grit/tag.rb

Overview

Head

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, commit) ⇒ Tag

Instantiate a new Tag

+name+ is the name of the head
+commit+ is the Commit that the head points to

Returns Grit::Tag (baked)



12
13
14
15
# File 'lib/grit/tag.rb', line 12

def initialize(name, commit)
  @name = name
  @commit = commit
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



5
6
7
# File 'lib/grit/tag.rb', line 5

def commit
  @commit
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/grit/tag.rb', line 4

def name
  @name
end

Class Method Details

.find_all(repo, options = {}) ⇒ Object

Find all Tags

+repo+ is the Repo
+options+ is a Hash of options

Returns Grit::Tag[] (baked)



22
23
24
25
26
27
28
29
30
31
# File 'lib/grit/tag.rb', line 22

def self.find_all(repo, options = {})
  default_options = {:sort => "committerdate",
                     :format => "%(refname)%00%(objectname)"}
                     
  actual_options = default_options.merge(options)
  
  output = repo.git.for_each_ref(actual_options, "refs/tags")
             
  self.list_from_string(repo, output)
end

.from_string(repo, line) ⇒ Object

Create a new Tag instance from the given string.

+repo+ is the Repo
+line+ is the formatted tag information

Format

name: [a-zA-Z_/]+
<null byte>
id: [0-9A-Fa-f]{40}

Returns Grit::Tag (baked)



58
59
60
61
62
63
# File 'lib/grit/tag.rb', line 58

def self.from_string(repo, line)
  full_name, id = line.split("\0")
  name = full_name.split("/").last
  commit = Commit.create(repo, :id => id)
  self.new(name, commit)
end

.list_from_string(repo, text) ⇒ Object

Parse out tag information into an array of baked Tag objects

+repo+ is the Repo
+text+ is the text output from the git command

Returns Grit::Tag[] (baked)



38
39
40
41
42
43
44
45
46
# File 'lib/grit/tag.rb', line 38

def self.list_from_string(repo, text)
  tags = []
  
  text.split("\n").each do |line|
    tags << self.from_string(repo, line)
  end
  
  tags
end

Instance Method Details

#inspectObject

Pretty object inspection



66
67
68
# File 'lib/grit/tag.rb', line 66

def inspect
  %Q{#<Grit::Tag "#{@name}">}
end