Datag 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
data/Datag.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Datag/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Datag"
8
+ s.version = Datag::VERSION
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = "https://github.com/da99/Datag"
12
+ s.summary = %q{ Print out previous/next git tags. }
13
+ s.description = %q{
14
+ Print out your previous/next git tags: Datag.next, Datag.previous.
15
+ }
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'bacon'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'Bacon_Colored'
25
+ s.add_development_dependency 'pry'
26
+
27
+ # Specify any dependencies here; for example:
28
+ s.add_runtime_dependency 'Exit_Zero'
29
+ s.add_runtime_dependency 'Split_Lines'
30
+ s.add_runtime_dependency 'trollop'
31
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+
2
+ Datag: da99's git tagger as a Ruby gem
3
+ ================
4
+
5
+ A Ruby gem to print previous/next git tags: v1.0, v2.1.0, etc.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ gem install Datag
11
+
12
+ Usage: Ruby
13
+ ------
14
+
15
+ require "Datag"
16
+
17
+ Datag.list => [ "v1.0.0", "v1.2.4", "v1.11.0", "v2.0.0", "v9.0.0" ]
18
+
19
+ system "git checkout v2.0.0"
20
+
21
+ Datag.next => "v9.0.0"
22
+ Datag.previous => "v1.11.0"
23
+
24
+ Datag.bump_patch => "v9.0.1"
25
+ Datag.bump_minor => "v9.1.0"
26
+ Datag.bump_major => "v10.0.0"
27
+
28
+ Usage: Shell
29
+ -----
30
+
31
+ Datag list
32
+ Datag list -r # Reverse the order.
33
+
34
+ Datag first # oldest: v1.0.0
35
+ Datag last # newest: v9.0.0
36
+
37
+ Datag next
38
+ Datag previous
39
+
40
+ git checkout $( Datag next )
41
+
42
+ git tag $( Datag bump_patch )
43
+ git tag $( Datag bump_minor )
44
+ git tag $( Datag bump_major )
45
+
46
+ Run Tests
47
+ ---------
48
+
49
+ git clone git@github.com:da99/Datag.git
50
+ cd Datag
51
+ bundle update
52
+ bundle exec bacon spec/main.rb
53
+
54
+ "I hate writing."
55
+ -----------------------------
56
+
57
+ If you know of existing software that makes the above redundant,
58
+ please tell me. The last thing I want to do is maintain code.
59
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
data/bin/Datag ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+ #
4
+
5
+ require 'Datag'
6
+ require 'trollop'
7
+
8
+ opts = Trollop::options do
9
+
10
+ opt :reverse, "Reverse the output of :list. Ignored for all other commands.", :default => false
11
+
12
+ end
13
+
14
+ if ARGV.first == "list" && opts[:reverse]
15
+ puts Datag.send(*ARGV).reverse
16
+ else
17
+ puts Datag.send(*ARGV)
18
+ end
data/lib/Datag.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'Datag/version'
2
+ require 'Exit_Zero'
3
+ require 'Split_Lines'
4
+
5
+ class Datag
6
+
7
+ module DSL
8
+
9
+ def list
10
+ Split_Lines(Exit_0("git tag -l").out)
11
+ .select { |str|
12
+ str[ %r!v[\d\.]! ]
13
+ }
14
+ .sort_by { |str|
15
+ to_arr str
16
+ }
17
+ end
18
+
19
+ def next
20
+ move 1
21
+ end
22
+
23
+ def previous
24
+ move -1
25
+ end
26
+
27
+ def first
28
+ list.first
29
+ end
30
+
31
+ def last
32
+ list.last
33
+ end
34
+
35
+ def move count
36
+ c = current
37
+ l = list
38
+ i = list.index(c.split('-').first)
39
+ return c if i.nil? || (i == 0 && count < 0)
40
+ t = l[ i + count ]
41
+ return c if t.nil?
42
+ t
43
+ end
44
+
45
+ def current
46
+ Exit_0('git describe --tag').out
47
+ end
48
+
49
+ def bump_patch
50
+ mj, m, p = to_arr( last! )
51
+ to_str mj, m, p + 1
52
+ end
53
+
54
+ def bump_minor
55
+ mj, m, p = to_arr( last! )
56
+ to_str mj, m + 1, 0
57
+ end
58
+
59
+ def bump_major
60
+ mj, m, p = to_arr( last! )
61
+ to_str mj + 1, 0, 0
62
+ end
63
+
64
+ def to_arr str
65
+ mj, m, p = str.sub('v', '').split( '.' ).map(&:to_i)
66
+ [ (mj || 0), (m || 0), (p || 0) ]
67
+ end
68
+
69
+ def to_str *arr
70
+ "v" + arr.flatten.join('.')
71
+ end
72
+
73
+ def last!
74
+ list.last || "v0.0.0"
75
+ end
76
+
77
+ end # === DSL
78
+
79
+ extend DSL
80
+
81
+ end # === class Datag
@@ -0,0 +1,3 @@
1
+ class Datag
2
+ VERSION = "1.0.0"
3
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.print e.message, "\n"
7
+ $stderr.print "Run `bundle install` to install missing gems\n"
8
+ exit e.status_code
9
+ end
10
+ require 'bacon'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ Bacon.summary_on_exit
data/spec/main.rb ADDED
@@ -0,0 +1,71 @@
1
+
2
+ require File.expand_path('spec/helper')
3
+ require 'Datag'
4
+ require 'Bacon_Colored'
5
+ require 'pry'
6
+ require 'pty'
7
+
8
+ TMP = "/tmp/Datag"
9
+ Me_List = %w{
10
+ v1.1.1
11
+ v1.2.1
12
+ v1.11.0
13
+ v2.0.0
14
+ v2.0.1
15
+ v2.0.02
16
+ }
17
+
18
+ class Test_Datag
19
+ include Datag::DSL
20
+ end
21
+
22
+ def chdir str = ''
23
+ Dir.chdir(File.join TMP, str) { yield }
24
+ end
25
+
26
+ def reset_tmp
27
+
28
+ Exit_0 "
29
+ rm -rf #{TMP}
30
+ mkdir -p #{TMP}
31
+ "
32
+ chdir {
33
+ Exit_0 %^
34
+ mkdir Me
35
+ cd Me
36
+ git init
37
+ touch Readme.md
38
+ git add .
39
+ git commit -m "First commit."
40
+ git tag First_Commit
41
+
42
+ cd ..
43
+ mkdir Zerrol
44
+ cd Zerrol
45
+ git init
46
+ ^
47
+ }
48
+
49
+ Me_List.each_with_index { |v, i|
50
+ chdir('Me') {
51
+ Exit_0 %^
52
+ touch #{v}.md
53
+ git add .
54
+ git commit -m "#{i} commit: #{v}"
55
+ git tag #{v}
56
+ ^
57
+ }
58
+ }
59
+
60
+ end # === def reset_tmp
61
+
62
+ reset_tmp
63
+
64
+ # ======== Include the tests.
65
+ if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
66
+ # Do nothing. Bacon grabs the file.
67
+ else
68
+ Dir.glob('spec/tests/*.rb').each { |file|
69
+ require File.expand_path(file.sub('.rb', '')) if File.file?(file)
70
+ }
71
+ end
@@ -0,0 +1,176 @@
1
+
2
+ describe "Datag :list" do
3
+
4
+ it "only lists tags containing characters: v 0-9 ." do
5
+ chdir('Me') {
6
+ Datag.list.should == Me_List
7
+ }
8
+ end
9
+
10
+ it "uses natural sorting" do
11
+ chdir('Me') {
12
+ Datag.list.should == Me_List
13
+ }
14
+ end
15
+
16
+ end # === describe Datag list
17
+
18
+ describe "Datag :next" do
19
+
20
+ it "lists tag previous to the current checked out tag." do
21
+ chdir('Me') {
22
+ Exit_0 %^ git checkout v2.0.1 ^
23
+ Datag.next.should == "v2.0.02"
24
+ }
25
+ end
26
+
27
+ it "returns current tag if it is the last tag." do
28
+ chdir('Me') {
29
+ Exit_0 %^ git checkout v2.0.02 ^
30
+ Datag.next.should == "v2.0.02"
31
+ }
32
+ end
33
+
34
+ it "returns current tag if on a non-tag commit" do
35
+ chdir('Me') {
36
+ Exit_0 %^
37
+ git checkout master
38
+ touch #{rand 1000}.md
39
+ git add .
40
+ git commit -m "No tag."
41
+ ^
42
+ Datag.next.should == Exit_0('git describe --tag').out
43
+ }
44
+ end
45
+
46
+ end # === Datag :next
47
+
48
+ describe "Datag :previous" do
49
+
50
+ it "lists tag previous to the current checked out tag." do
51
+ chdir('Me') {
52
+ Exit_0 %^ git checkout v2.0.02 ^
53
+ Datag.previous.should == "v2.0.1"
54
+ }
55
+ end
56
+
57
+ it "returns current tag if it is the first tag." do
58
+ chdir('Me') {
59
+ Exit_0 %^ git checkout v1.1.1 ^
60
+ Datag.previous.should == "v1.1.1"
61
+ }
62
+ end
63
+
64
+ it "returns previous tag if on a non-tag commit" do
65
+ chdir('Me') {
66
+ Exit_0 %^
67
+ git checkout master
68
+ touch #{rand 1000}.md
69
+ git add .
70
+ git commit -m "No tag."
71
+ ^
72
+ Datag.previous.should == "v2.0.1"
73
+ }
74
+ end
75
+
76
+ end # === Datag :previous
77
+
78
+ describe "Datag :bump_patch" do
79
+
80
+ after { reset_tmp }
81
+
82
+ it "adds 1 to patch of last tag" do
83
+ chdir('Me') {
84
+ Datag.bump_patch
85
+ .should == "v2.0.3"
86
+ }
87
+ end
88
+
89
+ it "adds 1 to patch if last tag is missing patch: v4.0" do
90
+ t = Test_Datag.new
91
+ def t.list
92
+ %w{ v4.0 }
93
+ end
94
+ t.bump_patch
95
+ .should == "v4.0.1"
96
+ end
97
+
98
+ it "returns v0.0.1 if no tags are listed" do
99
+ t = Test_Datag.new
100
+ def t.list
101
+ %w{}
102
+ end
103
+ t.bump_patch.should == "v0.0.1"
104
+ end
105
+
106
+ end # === Datag :bump_patch
107
+
108
+ describe "Datag :bump_minor" do
109
+
110
+ it "adds 1 to minor and sets patch to 0 of last tag" do
111
+ chdir('Me') {
112
+ Datag.bump_minor.should == "v2.1.0"
113
+ }
114
+ end
115
+
116
+ it "adds 1 to minor, even if last tag is missing a minor: v2" do
117
+ t = Test_Datag.new
118
+ def t.list
119
+ %w{ v1.0 v2 }
120
+ end
121
+ t.bump_minor.should == "v2.1.0"
122
+ end
123
+
124
+ it "returns v0.1.0 if no tags are listed" do
125
+ t = Test_Datag.new
126
+ def t.list
127
+ %w{ }
128
+ end
129
+ t.bump_minor.should == "v0.1.0"
130
+ end
131
+
132
+ end # === Datag :bump_minor
133
+
134
+ describe "Datag :bump_major" do
135
+
136
+ it "adds 1 to major" do
137
+ chdir('Me') {
138
+ Datag.bump_major.should == "v3.0.0"
139
+ }
140
+ end
141
+
142
+ it "returns v1.0.0 if no tags are found" do
143
+ t = Test_Datag.new
144
+ def t.list
145
+ %w{}
146
+ end
147
+ t.bump_major.should == "v1.0.0"
148
+ end
149
+
150
+ end # === Datag :bump_major
151
+
152
+ describe "Datag :first" do
153
+
154
+ it "prints first tag" do
155
+ t = Test_Datag.new
156
+ def t.list
157
+ %w{ v1 }
158
+ end
159
+ t.first.should == "v1"
160
+ end
161
+
162
+ end # === describe Datag :first
163
+
164
+ describe "Datag :last" do
165
+
166
+ it "prints last tag" do
167
+ t = Test_Datag.new
168
+ def t.list
169
+ %w{ v1 v2 }
170
+ end
171
+ t.last.should == "v2"
172
+ end
173
+
174
+ end # === Datag :last
175
+
176
+
data/spec/tests/bin.rb ADDED
@@ -0,0 +1,55 @@
1
+
2
+ describe "permissions of bin/" do
3
+ Dir.glob("bin/*").each { |file|
4
+ it "should chmod 755 for: #{file}" do
5
+ `stat -c %a #{file}`.strip
6
+ .should.be == "755"
7
+ end
8
+ }
9
+ end # === permissions of bin/
10
+
11
+
12
+ describe "Datag bin" do
13
+
14
+ it "prints out :next tag" do
15
+ chdir('Me') {
16
+ r = Exit_0 '
17
+ git checkout v1.1.1
18
+ bundle exec Datag next
19
+ '
20
+ r.raw_out.should == "v1.2.1\n"
21
+ }
22
+ end
23
+
24
+ it "prints out :previous tag" do
25
+ chdir('Me') {
26
+ r = Exit_0 '
27
+ git checkout v2.0.0
28
+ bundle exec Datag previous
29
+ '
30
+ r.raw_out.should == "v1.11.0\n"
31
+ }
32
+ end
33
+
34
+ it "prints each tag on a separate line" do
35
+ chdir('Me') {
36
+ Exit_0("bundle exec Datag list")
37
+ .raw_out.should == Me_List.join("\n") + "\n"
38
+ }
39
+ end
40
+
41
+ it "prints all tags reversed when passed: list -r" do
42
+ chdir('Me') {
43
+ Exit_0("bundle exec Datag list -r")
44
+ .raw_out.should == Me_List.reverse.join("\n") + "\n"
45
+ }
46
+ end
47
+
48
+ it "prints all tags reversed when passed: -r list" do
49
+ chdir('Me') {
50
+ Exit_0("bundle exec Datag -r list")
51
+ .raw_out.should == Me_List.reverse.join("\n") + "\n"
52
+ }
53
+ end
54
+
55
+ end # === Datag bin
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Datag
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: Bacon_Colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: Exit_Zero
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: Split_Lines
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: trollop
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: ! "\n Print out your previous/next git tags: Datag.next, Datag.previous.\n
127
+ \ "
128
+ email:
129
+ - i-hate-spam-45671204@mailinator.com
130
+ executables:
131
+ - Datag
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - Datag.gemspec
137
+ - Gemfile
138
+ - README.md
139
+ - Rakefile
140
+ - bin/Datag
141
+ - lib/Datag.rb
142
+ - lib/Datag/version.rb
143
+ - spec/helper.rb
144
+ - spec/main.rb
145
+ - spec/tests/Datag.rb
146
+ - spec/tests/bin.rb
147
+ homepage: https://github.com/da99/Datag
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.23
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Print out previous/next git tags.
171
+ test_files: []