Class: Plus2GitTagger::Tags
- Inherits:
-
Struct
- Object
- Struct
- Plus2GitTagger::Tags
- Defined in:
- lib/plus2_git_tagger/tags.rb
Instance Attribute Summary collapse
-
#git_helper ⇒ Object
Returns the value of attribute git_helper.
-
#tag_prefix ⇒ Object
Returns the value of attribute tag_prefix.
Instance Method Summary collapse
- #banner(*msgs) ⇒ Object
-
#base_tag ⇒ Object
Returns the base tag for today’s date.
-
#extensions ⇒ Object
Returns a sorted list of possible extensions.
-
#git(cmd) ⇒ Object
delegate to git helper.
- #git_s(cmd) ⇒ Object
-
#list ⇒ Object
Lists all tags matching the patten.
- #make! ⇒ Object
-
#month_list ⇒ Object
List all tags made this month.
-
#month_pattern ⇒ Object
Returns a pattern we can use to determine all tags for the month.
-
#next_tag(tag) ⇒ Object
Given a tag, using all the rules, find the next tag.
-
#tag_ext(tag) ⇒ Object
Extracts the extension from a tag.
-
#tag_regex ⇒ Object
Returns a regex which matches tags in the required format, and starting with ‘tag_prefix`.
-
#tags_with_pattern ⇒ Object
Returns tags matching ‘tag_regex` for this repo.
-
#this_months_tags ⇒ Object
Returns all tags for the month.
-
#todays_tags ⇒ Object
Returns a list matching the ‘tag_prefix`, on today’s date.
Instance Attribute Details
#git_helper ⇒ Object
Returns the value of attribute git_helper
2 3 4 |
# File 'lib/plus2_git_tagger/tags.rb', line 2 def git_helper @git_helper end |
#tag_prefix ⇒ Object
Returns the value of attribute tag_prefix
2 3 4 |
# File 'lib/plus2_git_tagger/tags.rb', line 2 def tag_prefix @tag_prefix end |
Instance Method Details
#banner(*msgs) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/plus2_git_tagger/tags.rb', line 25 def (*msgs) width = msgs.map {|m| m.size}.max = "*" * (width + 6) puts puts msgs.each do |m| print "* #{m}" print " " * (width - m.size + 2) puts "*" end puts puts end |
#base_tag ⇒ Object
Returns the base tag for today’s date.
Example:
di/rel-2011-07-07
88 89 90 |
# File 'lib/plus2_git_tagger/tags.rb', line 88 def base_tag Time.now.strftime("#{ tag_prefix }-%Y-%m-%d") end |
#extensions ⇒ Object
Returns a sorted list of possible extensions.
112 113 114 |
# File 'lib/plus2_git_tagger/tags.rb', line 112 def extensions ('1'..'9').to_a + ('a'..'z').to_a end |
#git(cmd) ⇒ Object
delegate to git helper
132 133 134 |
# File 'lib/plus2_git_tagger/tags.rb', line 132 def git(cmd) git_helper.git( cmd ) end |
#git_s(cmd) ⇒ Object
137 138 139 |
# File 'lib/plus2_git_tagger/tags.rb', line 137 def git_s(cmd) git_helper.git_s( cmd ) end |
#list ⇒ Object
Lists all tags matching the patten
68 69 70 71 72 |
# File 'lib/plus2_git_tagger/tags.rb', line 68 def list .sort.each do |tag| puts tag end end |
#make! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/plus2_git_tagger/tags.rb', line 5 def make! if last_tag = .sort.last tag = next_tag(last_tag) else tag = base_tag end luser = git_s("config user.name").chomp git "tag -m'auto-tagged by #{luser}' #{tag}" "Behold a tag! #{ tag }" git "push origin --tags" "Your tag has been pushed automatically.", "Please don't forget to push your current branch too!" end |
#month_list ⇒ Object
List all tags made this month
76 77 78 79 80 |
# File 'lib/plus2_git_tagger/tags.rb', line 76 def month_list .sort.each do |tag| puts tag end end |
#month_pattern ⇒ Object
Returns a pattern we can use to determine all tags for the month
100 101 102 |
# File 'lib/plus2_git_tagger/tags.rb', line 100 def month_pattern Time.now.strftime("#{ tag_prefix }-%Y-%m") end |
#next_tag(tag) ⇒ Object
Given a tag, using all the rules, find the next tag.
45 46 47 48 49 50 |
# File 'lib/plus2_git_tagger/tags.rb', line 45 def next_tag(tag) last_index = extensions.index( tag_ext(tag) ) || -1 next_ext = extensions[last_index+1] "#{base_tag}-#{next_ext}" end |
#tag_ext(tag) ⇒ Object
Extracts the extension from a tag
Returns either the extension, or a blank string.
120 121 122 123 124 125 126 127 |
# File 'lib/plus2_git_tagger/tags.rb', line 120 def tag_ext(tag) ext = tag.sub(tag_regex, '') if ext[0] == ?- ext[1].chr else '' end end |
#tag_regex ⇒ Object
Returns a regex which matches tags in the required format, and starting with ‘tag_prefix`.
56 57 58 |
# File 'lib/plus2_git_tagger/tags.rb', line 56 def tag_regex @tag_regex ||= %r{^#{ Regexp.quote tag_prefix }-\d{4}-\d{2}-\d{2}} end |
#tags_with_pattern ⇒ Object
Returns tags matching ‘tag_regex` for this repo.
62 63 64 |
# File 'lib/plus2_git_tagger/tags.rb', line 62 def git_helper..grep(tag_regex) end |
#this_months_tags ⇒ Object
Returns all tags for the month
106 107 108 |
# File 'lib/plus2_git_tagger/tags.rb', line 106 def .grep(%r{^#{ month_pattern }}) end |
#todays_tags ⇒ Object
Returns a list matching the ‘tag_prefix`, on today’s date.
94 95 96 |
# File 'lib/plus2_git_tagger/tags.rb', line 94 def .grep(%r{^#{ base_tag }}) end |