technicalpickles-jeweler 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jeweler/active_support.rb +1 -1
- data/lib/jeweler/tasks.rb +25 -13
- data/lib/jeweler/version.rb +1 -1
- data/lib/jeweler.rb +54 -34
- metadata +1 -1
data/lib/jeweler/tasks.rb
CHANGED
@@ -1,37 +1,49 @@
|
|
1
1
|
desc "Generate a gemspec file for GitHub"
|
2
2
|
task :gemspec do
|
3
|
-
Jeweler.write_gemspec
|
3
|
+
Jeweler.instance.write_gemspec
|
4
4
|
end
|
5
5
|
|
6
6
|
desc "Displays the current version"
|
7
7
|
task :version do
|
8
|
-
puts Jeweler.version
|
8
|
+
puts Jeweler.instance.version
|
9
9
|
end
|
10
10
|
|
11
11
|
namespace :version do
|
12
12
|
namespace :bump do
|
13
13
|
desc "Bump the gemspec a major version."
|
14
14
|
task :major do
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
jeweler = Jeweler.instance
|
16
|
+
|
17
|
+
major = jeweler.major_version + 1
|
18
|
+
|
19
|
+
jeweler.bump_version(major, 0, 0)
|
20
|
+
jeweler.write_gemspec
|
21
|
+
|
18
22
|
puts "Version bumped to #{Jeweler.version}"
|
19
23
|
end
|
20
24
|
|
21
25
|
desc "Bump the gemspec a minor version."
|
22
26
|
task :minor do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
jeweler = Jeweler.instance
|
28
|
+
|
29
|
+
minor = jeweler.minor_version + 1
|
30
|
+
|
31
|
+
jeweler.bump_version(jeweler.major_version, minor, 0)
|
32
|
+
jeweler.write_gemspec
|
33
|
+
|
34
|
+
puts "Version bumped to #{jeweler.version}"
|
27
35
|
end
|
28
36
|
|
29
37
|
desc "Bump the gemspec a patch version."
|
30
38
|
task :patch do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
jeweler = Jeweler.instance
|
40
|
+
|
41
|
+
patch = jeweler.patch_version + 1
|
42
|
+
|
43
|
+
jeweler.bump_version(jeweler.major_version, jeweler.minor_version, patch)
|
44
|
+
jeweler.write_gemspec
|
45
|
+
|
46
|
+
puts "Version bumped to #{jeweler.version}"
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
data/lib/jeweler/version.rb
CHANGED
data/lib/jeweler.rb
CHANGED
@@ -2,43 +2,47 @@ require 'date'
|
|
2
2
|
|
3
3
|
class Jeweler
|
4
4
|
def self.gemspec=(gemspec)
|
5
|
-
@@
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
@@instance = new(gemspec)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
@@instance
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :gemspec
|
13
|
+
def initialize(gemspec)
|
14
|
+
@gemspec = gemspec
|
15
|
+
|
16
|
+
load_version()
|
17
|
+
|
18
|
+
@gemspec.version = version
|
19
|
+
@gemspec.files ||= FileList["[A-Z]*", "{generators,lib,test,spec}/**/*"]
|
9
20
|
end
|
10
21
|
|
11
|
-
def
|
22
|
+
def major_version
|
12
23
|
version_module.const_get(:MAJOR)
|
13
24
|
end
|
14
25
|
|
15
|
-
def
|
26
|
+
def minor_version
|
16
27
|
version_module.const_get(:MINOR)
|
17
28
|
end
|
18
29
|
|
19
|
-
def
|
30
|
+
def patch_version
|
20
31
|
version_module.const_get(:PATCH)
|
21
32
|
end
|
22
33
|
|
23
|
-
def
|
34
|
+
def version
|
24
35
|
"#{major_version}.#{minor_version}.#{patch_version}"
|
25
36
|
end
|
26
37
|
|
27
|
-
def
|
38
|
+
def date
|
28
39
|
date = DateTime.now
|
29
40
|
"#{date.year}-#{date.month}-#{date.day}"
|
30
41
|
end
|
31
42
|
|
32
|
-
def
|
43
|
+
def bump_version(major, minor, patch)
|
33
44
|
main_module_or_class = constantize(main_module_name)
|
34
|
-
keyword =
|
35
|
-
when Class
|
36
|
-
'class'
|
37
|
-
when Module
|
38
|
-
'module'
|
39
|
-
else
|
40
|
-
raise "Uh, main_module_name should be a class or module, but was a #{main_module_or_class.class}"
|
41
|
-
end
|
45
|
+
keyword = top_level_keyword
|
42
46
|
|
43
47
|
File.open(version_module_path, 'w') do |file|
|
44
48
|
file.write <<-END
|
@@ -51,46 +55,62 @@ class Jeweler
|
|
51
55
|
end
|
52
56
|
END
|
53
57
|
end
|
54
|
-
|
58
|
+
@gemspec.version = "#{major}.#{minor}.#{patch}"
|
55
59
|
refresh_version
|
56
60
|
end
|
57
61
|
|
58
|
-
def
|
59
|
-
|
62
|
+
def write_gemspec
|
63
|
+
@gemspec.date = self.date
|
60
64
|
File.open(gemspec_path, 'w') do |f|
|
61
|
-
f.write
|
65
|
+
f.write @gemspec.to_ruby
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
69
|
private
|
66
70
|
|
67
|
-
def
|
68
|
-
|
71
|
+
def top_level_keyword
|
72
|
+
main_module_or_class = constantize(main_module_name)
|
73
|
+
case main_module_or_class
|
74
|
+
when Class
|
75
|
+
'class'
|
76
|
+
when Module
|
77
|
+
'module'
|
78
|
+
else
|
79
|
+
raise "Uh, main_module_name should be a class or module, but was a #{main_module_or_class.class}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def gemspec_path
|
84
|
+
"#{@gemspec.name}.gemspec"
|
69
85
|
end
|
70
86
|
|
71
|
-
def
|
72
|
-
"lib/#{
|
87
|
+
def version_module_path
|
88
|
+
"lib/#{@gemspec.name}/version.rb"
|
73
89
|
end
|
74
90
|
|
75
|
-
def
|
91
|
+
def version_module
|
76
92
|
constantize("#{main_module_name}::Version")
|
77
93
|
end
|
78
94
|
|
79
|
-
def
|
80
|
-
camelize(
|
95
|
+
def main_module_name
|
96
|
+
camelize(@gemspec.name)
|
81
97
|
end
|
82
98
|
|
83
|
-
def
|
99
|
+
def refresh_version
|
84
100
|
# Remove the constants, so we can reload the version_module
|
85
101
|
version_module.module_eval do
|
86
|
-
remove_const(:MAJOR)
|
87
|
-
remove_const(:MINOR)
|
88
|
-
remove_const(:PATCH)
|
102
|
+
remove_const(:MAJOR) if const_defined?(:MAJOR)
|
103
|
+
remove_const(:MINOR) if const_defined?(:MINOR)
|
104
|
+
remove_const(:PATCH) if const_defined?(:PATCH)
|
89
105
|
end
|
106
|
+
load_version
|
107
|
+
end
|
108
|
+
|
109
|
+
def load_version
|
90
110
|
load version_module_path
|
91
111
|
end
|
92
112
|
end
|
93
113
|
|
94
114
|
require 'jeweler/active_support' # Adds the stolen camelize and constantize
|
95
115
|
|
96
|
-
require 'jeweler/tasks'
|
116
|
+
require 'jeweler/tasks' if defined?(Rake)
|