gem_polish 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +17 -8
- data/bin/gem_polish +7 -0
- data/gem_polish.gemspec +2 -2
- data/lib/gem_polish/cli/versioner.rb +78 -0
- data/lib/gem_polish/cli.rb +45 -8
- data/lib/gem_polish/version.rb +1 -1
- data/spec/lib/gem_polish/cli/versioner_spec.rb +81 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c31a47f214bd4cbda2e76e059444aafa3adbb0d
|
4
|
+
data.tar.gz: 4cb8604e6284d299348292047c7338b121a089a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2e88c89011f2461ffb435f551d4933a9a6e5759dc7e9ddbe0cef7de50c97d186a2d366407206f20324e52509b301cec4d2680691339a68e4eef04606541a3a
|
7
|
+
data.tar.gz: 2f998d5155526a21c6aa83f51a48ebad07d88d000f9836a048ac32558b6d6f1ba595e0238f02d9c4eef78e95a8c038ab624f575d0245f3f9212c3812926677d2
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# GemPolish
|
2
2
|
|
3
|
-
|
3
|
+
Command line tool to help with gem creation and maintenance. Is meant to be used in
|
4
|
+
addition to `bundler`'s `gem` command.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -8,9 +9,9 @@ Further polishes your Bundler gem skeleton.
|
|
8
9
|
|
9
10
|
## Usage
|
10
11
|
|
11
|
-
Provides
|
12
|
+
Provides the executable `gem_polish`, which boasts the following subcommands:
|
12
13
|
|
13
|
-
-
|
14
|
+
- __polish__
|
14
15
|
|
15
16
|
Is meant to be used inside the directory a newly created gem (`bundle gem GEM_NAME`)
|
16
17
|
Available options:
|
@@ -32,27 +33,35 @@ for gem polishing. Check the `examples` folder for its formatting.
|
|
32
33
|
Here's an example of the syntax:
|
33
34
|
```
|
34
35
|
# inside a new gem called test
|
35
|
-
|
36
|
+
gem_polish polish -nc -d 'a test gem' -t 1.9.3 jruby-1.7.8 -b travis coveralls
|
36
37
|
```
|
37
38
|
This would polish the test gem with coveralls support,
|
38
39
|
circumventing the `.gem_polish.yml` file, adding a description,
|
39
40
|
using two ruby versions for travis and adding two badges to the
|
40
41
|
README file.
|
41
42
|
|
43
|
+
For ease of use you can issue `polish_gem` instead of `gem_polish
|
44
|
+
polish` directly on the command line.
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
Combines gem creation and polishing:
|
46
|
+
The additional executable `create_gem` combines gem creation and polishing:
|
46
47
|
```
|
47
48
|
create_gem my_new_gem
|
48
49
|
```
|
49
|
-
This will create the new gem `my_new_gem`. Arguments of `polish_gem` can
|
50
|
+
This will create the new gem `my_new_gem`. Arguments of `polish_gem` can
|
51
|
+
be passed to override defaults or to provide a description.
|
50
52
|
```
|
51
53
|
create_gem my_new_gem -d 'Does nothing so far'
|
52
54
|
```
|
53
55
|
At the moment he `bundle gem` command is invoked with `-t rspec` to
|
54
56
|
provide the `rspec` test framework by default.
|
55
57
|
|
58
|
+
- __version__
|
59
|
+
|
60
|
+
Provides a version reader and a version bumper. Call `gem_polish
|
61
|
+
version` to learn about its usage. Also includes support to commit your
|
62
|
+
version bump directly through `git`.
|
63
|
+
|
64
|
+
|
56
65
|
## Contributing
|
57
66
|
|
58
67
|
1. Fork it ( http://github.com/LFDM/gem_polish/fork )
|
data/bin/gem_polish
ADDED
data/gem_polish.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = GemPolish::VERSION
|
9
9
|
spec.authors = ["LFDM"]
|
10
10
|
spec.email = ["1986gh@gmail.com"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{Adds code coverage tools, badges in README,
|
11
|
+
spec.summary = %q{Command line tool to help with gem creation and maintenance}
|
12
|
+
spec.description = %q{Adds code coverage tools, badges in README, help with travis, gem versioning etc.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module GemPolish
|
2
|
+
class CLI::Versioner
|
3
|
+
def initialize(thor)
|
4
|
+
@thor = thor
|
5
|
+
@version = extract_from_version_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def extract_from_version_file
|
9
|
+
file_contents.match(regexp)
|
10
|
+
numbers = $1.split('.').map(&:to_i)
|
11
|
+
Hash[%w{ major minor revision}.zip(numbers)]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_version(hsh = @version)
|
15
|
+
hsh.values.join('.')
|
16
|
+
end
|
17
|
+
|
18
|
+
def substitute_version(v)
|
19
|
+
version = v.kind_of?(String) ? v : to_version(v)
|
20
|
+
@thor.gsub_file(file, regexp, insertion(version))
|
21
|
+
@thor.say_status(:bumped_version, "#{to_version} => #{version}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_version(bumper)
|
25
|
+
set_back = false
|
26
|
+
@version.each_with_object({}) do |(level, number), h|
|
27
|
+
nl = if set_back
|
28
|
+
0
|
29
|
+
else
|
30
|
+
if level == bumper
|
31
|
+
set_back = true
|
32
|
+
number + 1
|
33
|
+
else
|
34
|
+
number
|
35
|
+
end
|
36
|
+
end
|
37
|
+
h[level] = nl
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def commit_version_bump(message)
|
42
|
+
if staged_files_present?
|
43
|
+
raise StandardError.new, "Commit aborted: Staged files present"
|
44
|
+
else
|
45
|
+
`git add #{file}`
|
46
|
+
`git commit -m "#{message}"`
|
47
|
+
sha = `git rev-parse --short HEAD`.chomp
|
48
|
+
@thor.say_status(:commited, %{#{sha} "#{message}"})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def gem_name
|
55
|
+
File.basename(Dir.pwd)
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_contents
|
59
|
+
File.read(file)
|
60
|
+
end
|
61
|
+
|
62
|
+
def file
|
63
|
+
"lib/#{gem_name}/version.rb"
|
64
|
+
end
|
65
|
+
|
66
|
+
def regexp
|
67
|
+
/VERSION = "(.*?)"/
|
68
|
+
end
|
69
|
+
|
70
|
+
def insertion(version)
|
71
|
+
%{VERSION = "#{version}"}
|
72
|
+
end
|
73
|
+
|
74
|
+
def staged_files_present?
|
75
|
+
system('git status --porcelain | grep -o "^\w" >/dev/null')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/gem_polish/cli.rb
CHANGED
@@ -3,16 +3,25 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module GemPolish
|
5
5
|
class CLI < Thor
|
6
|
+
|
7
|
+
require 'gem_polish/cli/versioner'
|
6
8
|
include Thor::Actions
|
7
9
|
|
8
|
-
desc "polish", "
|
9
|
-
method_option :badges, type: :array, aliases: '-b'
|
10
|
-
|
11
|
-
method_option :
|
12
|
-
|
13
|
-
method_option :
|
14
|
-
|
15
|
-
method_option :
|
10
|
+
desc "polish", "Polishes your gem skeleton"
|
11
|
+
method_option :badges, type: :array, aliases: '-b',
|
12
|
+
desc: 'Adds badges to your README. Takes one or more of: badge_fury, gemnasium, travis, coveralls and code_climate'
|
13
|
+
method_option :git_user, type: :string, aliases: '-g',
|
14
|
+
desc: 'Git user to be used for badge links. Defaults to your .gitconfig information'
|
15
|
+
method_option :description, aliases: '-d',
|
16
|
+
desc: 'Adds a descriptopn to the gemspec and the README'
|
17
|
+
method_option :coverage, aliases: '-c',
|
18
|
+
desc: 'Adds coveralls coverage'
|
19
|
+
method_option :rspec_conf, aliases: '-r',
|
20
|
+
desc: 'Adds additional rspec configuration'
|
21
|
+
method_option :travis, type: :array, aliases: '-t',
|
22
|
+
desc: 'Adds ruby versions to travis'
|
23
|
+
method_option :no_default, aliases: '-n',
|
24
|
+
desc: 'Bypasses ~/.gem_polish.yml. Defaults to false'
|
16
25
|
def polish(name = '.')
|
17
26
|
inside name do
|
18
27
|
default = options.has_key?('no_default') ? {} : def_conf
|
@@ -30,6 +39,34 @@ module GemPolish
|
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
42
|
+
desc 'version OPTION', 'Reads and writes the version file of your gem'
|
43
|
+
method_option :read, type: :boolean, aliases: '-r',
|
44
|
+
desc: 'Print current version number'
|
45
|
+
method_option :bump, aliases: '-b', lazy_default: 'revision',
|
46
|
+
desc: 'Bumps the version number (revision [default], minor or major)'
|
47
|
+
method_option :version, aliases: '-v',
|
48
|
+
desc: 'Specify the new version number directly'
|
49
|
+
method_option :commit, aliases: '-c', lazy_default: 'Bump version',
|
50
|
+
desc: 'Creates a git commit of a bump, takes a message, defaults to "Bump version"'
|
51
|
+
def version(name = '.')
|
52
|
+
inside name do
|
53
|
+
return help(:version) if options.empty?
|
54
|
+
v = Versioner.new(self)
|
55
|
+
|
56
|
+
if specified_version = options[:version]
|
57
|
+
v.substitute_version(specified_version)
|
58
|
+
elsif options[:read]
|
59
|
+
puts v.to_version
|
60
|
+
elsif bump = options[:bump]
|
61
|
+
updated = v.update_version(bump)
|
62
|
+
v.substitute_version(updated)
|
63
|
+
if message = options[:commit]
|
64
|
+
v.commit_version_bump(message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
33
70
|
no_commands do
|
34
71
|
def parse_opt(opt, opts, default)
|
35
72
|
opts[opt] || default[opt]
|
data/lib/gem_polish/version.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GemPolish::CLI::Versioner do
|
4
|
+
let(:versioner) { GemPolish::CLI::Versioner.new('') }
|
5
|
+
let(:version_file) do
|
6
|
+
<<-FILE
|
7
|
+
module Dummy
|
8
|
+
VERSION = "2.1.3"
|
9
|
+
end
|
10
|
+
FILE
|
11
|
+
end
|
12
|
+
let(:version_hash) do
|
13
|
+
{
|
14
|
+
'major' => 2,
|
15
|
+
'minor' => 1,
|
16
|
+
'revision' => 3,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#extract_from_version_file" do
|
21
|
+
it "returns current version as a hash" do
|
22
|
+
versioner.stub(:file_contents) { version_file }
|
23
|
+
versioner.extract_from_version_file.should == version_hash
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#to_version" do
|
28
|
+
it "converts a given version hash to a string" do
|
29
|
+
versioner.to_version(version_hash).should == "2.1.3"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns current version when no version hash is given" do
|
33
|
+
versioner.stub(:file_contents) { version_file }
|
34
|
+
versioner.instance_variable_set(:@version, versioner.extract_from_version_file)
|
35
|
+
versioner.to_version.should == "2.1.3"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#update_version" do
|
40
|
+
before(:each) do
|
41
|
+
versioner.stub(:file_contents) { version_file }
|
42
|
+
versioner.instance_variable_set(:@version, versioner.extract_from_version_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#returns an updated version hash for the given bumper" do
|
46
|
+
it "bumps revision" do
|
47
|
+
res = {
|
48
|
+
'major' => 2,
|
49
|
+
'minor' => 1,
|
50
|
+
'revision' => 4,
|
51
|
+
}
|
52
|
+
versioner.update_version('revision').should == res
|
53
|
+
end
|
54
|
+
|
55
|
+
it "bumps minor version" do
|
56
|
+
res = {
|
57
|
+
'major' => 2,
|
58
|
+
'minor' => 2,
|
59
|
+
'revision' => 0,
|
60
|
+
}
|
61
|
+
versioner.update_version('minor').should == res
|
62
|
+
end
|
63
|
+
|
64
|
+
it "bumps major version" do
|
65
|
+
res = {
|
66
|
+
'major' => 3,
|
67
|
+
'minor' => 0,
|
68
|
+
'revision' => 0,
|
69
|
+
}
|
70
|
+
versioner.update_version('major').should == res
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#commit_version_bump" do
|
76
|
+
it "raises an error when staged files are present" do
|
77
|
+
versioner.stub(:staged_files_present?) { true }
|
78
|
+
expect { versioner.commit_version_bump('') }.to raise_error StandardError, /aborted/
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_polish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LFDM
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,12 +66,13 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Adds code coverage tools, badges in README,
|
69
|
+
description: Adds code coverage tools, badges in README, help with travis, gem versioning
|
70
70
|
etc.
|
71
71
|
email:
|
72
72
|
- 1986gh@gmail.com
|
73
73
|
executables:
|
74
74
|
- create_gem
|
75
|
+
- gem_polish
|
75
76
|
- polish_gem
|
76
77
|
extensions: []
|
77
78
|
extra_rdoc_files: []
|
@@ -84,16 +85,19 @@ files:
|
|
84
85
|
- README.md
|
85
86
|
- Rakefile
|
86
87
|
- bin/create_gem
|
88
|
+
- bin/gem_polish
|
87
89
|
- bin/polish_gem
|
88
90
|
- examples/.gem_polish.yml
|
89
91
|
- gem_polish.gemspec
|
90
92
|
- gem_polish.thor
|
91
93
|
- lib/gem_polish.rb
|
92
94
|
- lib/gem_polish/cli.rb
|
95
|
+
- lib/gem_polish/cli/versioner.rb
|
93
96
|
- lib/gem_polish/version.rb
|
94
97
|
- lib/templates/coveralls.template
|
95
98
|
- lib/templates/rspec_configuration.template
|
96
99
|
- spec/gem_polish_spec.rb
|
100
|
+
- spec/lib/gem_polish/cli/versioner_spec.rb
|
97
101
|
- spec/spec_helper.rb
|
98
102
|
homepage: ''
|
99
103
|
licenses:
|
@@ -118,7 +122,8 @@ rubyforge_project:
|
|
118
122
|
rubygems_version: 2.2.0
|
119
123
|
signing_key:
|
120
124
|
specification_version: 4
|
121
|
-
summary:
|
125
|
+
summary: Command line tool to help with gem creation and maintenance
|
122
126
|
test_files:
|
123
127
|
- spec/gem_polish_spec.rb
|
128
|
+
- spec/lib/gem_polish/cli/versioner_spec.rb
|
124
129
|
- spec/spec_helper.rb
|