gembump 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 355dfae126c0209bce092449bf6acde2c667dc8a09496c842ac65ecd84c84d45
4
+ data.tar.gz: 479e29694473658afe9537881165a4cbb509a88b3f72654baaaef26be1ac0db6
5
+ SHA512:
6
+ metadata.gz: 297fa6ec8a4f3f7d8a631b4fd461e81d9e904474e788ba05479c0df589437fcf295a7d43ea46c85003b65cd0b40f939bf1b658c5f65a2d7a13f12c71e1d392e7
7
+ data.tar.gz: f8947873bef4720c7de784763e4946db02fe8db3577cc0ca890efdb6c83a618eba19fe63490828c3acf09673a23802bc0b763b79f334441ed32f24a509ccb0a7
@@ -0,0 +1,113 @@
1
+ class Gem::Commands::BumpCommand < Gem::Command
2
+ BUMP_METHODS = ["major", "minor", "patch"]
3
+
4
+ def initialize
5
+ super("bump", "Increases the version of a .gemspec file")
6
+ end
7
+
8
+ def usage
9
+ "#{program_name} [METHOD] FILE"
10
+ end
11
+
12
+ def arguments
13
+ <<-ARGUMENTS
14
+ METHOD version to update (major, minor, patch)
15
+ FILE name of the gemspec file (you can omit the .gemspec extension)
16
+ ARGUMENTS
17
+ end
18
+
19
+ def defaults_str
20
+ "METHOD patch"
21
+ end
22
+
23
+ def execute
24
+ bump_method = options[:args][0] || ""
25
+ gemspec = options[:args][1]
26
+
27
+ if BUMP_METHODS.include?(bump_method)
28
+ unless gemspec_exists?(gemspec)
29
+ puts "Invalid gemspec name specified"
30
+ show_help
31
+ return
32
+ end
33
+ else
34
+ unless gemspec_exists?(bump_method)
35
+ if gemspec_exists?(gemspec)
36
+ puts "Invalid bump method specified."
37
+ else
38
+ puts "Invalid gemspec name specified."
39
+ end
40
+ show_help
41
+ return
42
+ end
43
+ gemspec = bump_method
44
+ bump_method = "patch"
45
+ end
46
+ gemspec = gemspec_file(gemspec)
47
+ scrape_gemspec(gemspec)
48
+ bump_gemspec_version(bump_method)
49
+ write_gemspec_file(gemspec)
50
+ end
51
+
52
+ private
53
+
54
+ def gemspec_exists?(gemspec)
55
+ gemspec = gemspec_file(gemspec)
56
+ !gemspec.nil? && File.file?(gemspec)
57
+ end
58
+
59
+ def gemspec_file(file)
60
+ if File.file?(file)
61
+ file
62
+ else
63
+ name = "#{file}.gemspec"
64
+ File.file?(name) ? name : nil
65
+ end
66
+ end
67
+
68
+ def scrape_gemspec(gemspec_file)
69
+ File.open(gemspec_file, "r") do |f|
70
+ @gemspec_lines = f.readlines
71
+ end
72
+ @gemspec_lines.each_with_index do |l, i|
73
+ if /(.*\.version)\s*=\s*\"(\d(\.\d)*)\"/ =~ l
74
+ @version = {
75
+ number: $~[2],
76
+ line: i,
77
+ variable: $~[1]
78
+ }
79
+ break
80
+ end
81
+ end
82
+ end
83
+
84
+ def bump_gemspec_version(type = "patch")
85
+ versions = @version[:number].split(".").map(&:to_i)
86
+ (0..2).each do |i|
87
+ versions[i] ||= 0
88
+ versions[i] = [0,versions[i]].max
89
+ end
90
+ versions = versions[0..2]
91
+ case type
92
+ when "major"
93
+ versions[0] += 1
94
+ versions[1] = 0
95
+ versions[2] = 0
96
+ when "minor"
97
+ versions[1] += 1
98
+ versions[2] = 0
99
+ when "patch"
100
+ versions[2] += 1
101
+ end
102
+ @old_version = @version[:number]
103
+ @version[:number] = versions.join(".")
104
+ end
105
+
106
+ def write_gemspec_file(filename)
107
+ @gemspec_lines[@version[:line]] = "#{@version[:variable]} = \"#{@version[:number]}\"\n"
108
+ puts "Bumping #{filename.split(".")[0]} from #{@old_version} to #{@version[:number]}"
109
+ File.open(filename, "w") do |f|
110
+ f.write @gemspec_lines.join
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ require "rubygems/command_manager"
2
+
3
+ Gem::CommandManager.instance.register_command(:bump)
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gembump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kellen Watt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Rubygems plugin that allows you to bump the major, minor, and patch version
14
+ of your gem without editing the gemspec.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rubygems/commands/bump_command.rb
21
+ - lib/rubygems_plugin.rb
22
+ homepage: https://github.com/KellenWatt/gempbump
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.1.4
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Rubygems plugin to bump versioning automatically.
45
+ test_files: []