gem-release 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,9 @@ module GemRelease
6
6
  end
7
7
 
8
8
  def option(key, short, description)
9
- options = self.class::OPTIONS
10
- default = options[key]
9
+ default = self.class::DEFAULTS[key]
11
10
 
12
- if String === default
11
+ if default.is_a?(String)
13
12
  long = "--#{key} #{key.to_s.upcase}"
14
13
  args = [short, long, String, "#{description} (defaults to #{default})"]
15
14
  else
@@ -1,21 +1,22 @@
1
1
  module GemRelease
2
2
  class Gemspec < Template
3
- attr_reader :authors, :email, :homepage, :summary, :description
3
+ attr_reader :author, :email, :homepage, :summary, :description, :strategy
4
4
 
5
5
  def initialize(options = {})
6
- super
6
+ super('gemspec', options)
7
7
 
8
- @authors ||= [user_name]
8
+ @author ||= user_name
9
9
  @email ||= user_email
10
- @homepage ||= "http://github.com/#{github_user}/#{name}" || "[your github name]"
10
+ @homepage ||= "https://github.com/#{github_user}/#{name}" || "[your github name]"
11
11
 
12
12
  @summary ||= '[summary]'
13
13
  @description ||= '[description]'
14
+
14
15
  @strategy = options[:strategy]
15
16
  end
16
17
 
17
18
  def files
18
- case @strategy
19
+ case strategy
19
20
  when 'git'
20
21
  '`git ls-files app lib`.split("\n")'
21
22
  else
@@ -30,9 +31,5 @@ module GemRelease
30
31
  def filename
31
32
  "#{name}.gemspec"
32
33
  end
33
-
34
- def template_name
35
- 'gemspec.erb'
36
- end
37
34
  end
38
35
  end
@@ -2,6 +2,10 @@ require 'core_ext/string/camelize'
2
2
 
3
3
  module GemRelease
4
4
  module Helpers
5
+ def quiet?
6
+ options[:quiet]
7
+ end
8
+
5
9
  def user_name
6
10
  `git config --get user.name`.strip
7
11
  end
@@ -11,15 +15,15 @@ module GemRelease
11
15
  end
12
16
 
13
17
  def github_user
14
- @github_user ||= `git config --get github.user`.strip
18
+ `git config --get github.user`.strip
15
19
  end
16
20
 
17
21
  def github_token
18
- @github_token ||= `git config --get github.token`.strip
22
+ `git config --get github.token`.strip
19
23
  end
20
24
 
21
25
  def gem_name
22
- @gem_name ||= gemspec ? gemspec.name : gem_name_from_directory
26
+ gemspec ? gemspec.name : gem_name_from_directory
23
27
  end
24
28
 
25
29
  def gem_name_from_directory
@@ -27,11 +31,11 @@ module GemRelease
27
31
  end
28
32
 
29
33
  def gem_module_path
30
- @gem_module_path ||= gem_name.gsub('-', '_')
34
+ gem_name.gsub('-', '_')
31
35
  end
32
36
 
33
37
  def gem_module_name
34
- @gem_module_name ||= gem_module_path.camelize
38
+ gem_module_path.camelize
35
39
  end
36
40
 
37
41
  def gem_filename
@@ -43,17 +47,15 @@ module GemRelease
43
47
  end
44
48
 
45
49
  def gemspec
46
- @gemspec ||= Gem::Specification.load(gemspec_filename)
50
+ Gem::Specification.load(gemspec_filename)
47
51
  rescue LoadError, RuntimeError
48
52
  nil
49
53
  end
50
54
 
51
55
  def gemspec_filename
52
- @gemspec_filename ||= begin
53
- name = Array(options[:args]).first rescue nil
54
- name ||= Dir['*.gemspec'].first
55
- name || raise("No gemspec found or given.")
56
- end
56
+ name = Array(options[:args]).first rescue nil
57
+ name ||= Dir['*.gemspec'].first
58
+ name || raise("No gemspec found or given.")
57
59
  end
58
60
  end
59
61
  end
@@ -0,0 +1,18 @@
1
+ module GemRelease
2
+ class License < Template
3
+ attr_reader :author, :email, :year
4
+
5
+ def initialize(options = {})
6
+ super
7
+
8
+ @author ||= user_name
9
+ @email ||= user_email
10
+ @year ||= Time.now.year
11
+ end
12
+
13
+ def template_name
14
+ 'gemspec.erb'
15
+ end
16
+ end
17
+ end
18
+
@@ -6,11 +6,15 @@ module GemRelease
6
6
  class Template
7
7
  include GemRelease::Helpers
8
8
 
9
- attr_reader :name, :module_name, :module_path, :options
9
+ attr_reader :template, :name, :module_name, :module_path
10
10
 
11
- def initialize(options = {})
12
- @options = options
13
- options.each { |key, value| instance_variable_set(:"@#{key}", value) }
11
+ def initialize(template, options = {})
12
+ @template = template
13
+
14
+ options.each do |key, value|
15
+ instance_variable_set(:"@#{key}", value)
16
+ meta_class.send(:attr_reader, key)
17
+ end
14
18
 
15
19
  @name ||= gem_name_from_directory
16
20
  @module_path ||= name.gsub('-', '_')
@@ -22,12 +26,22 @@ module GemRelease
22
26
  File.open(filename, 'w+') { |f| f.write(render) }
23
27
  end
24
28
 
25
- def render
26
- ERB.new(template, nil, "%").result(binding)
27
- end
29
+ protected
28
30
 
29
- def template
30
- File.new(File.expand_path("../templates/#{template_name}", __FILE__)).read
31
- end
31
+ def filename
32
+ template
33
+ end
34
+
35
+ def render
36
+ ERB.new(read_template, nil, "%").result(binding)
37
+ end
38
+
39
+ def read_template
40
+ File.new(File.expand_path("../templates/#{template}", __FILE__)).read
41
+ end
42
+
43
+ def meta_class
44
+ class << self; self; end
45
+ end
32
46
  end
33
47
  end
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) <% year %> <%= author %> <<%= email %>>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -6,7 +6,7 @@ require '<%= module_path %>/version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = <%= name.inspect %>
8
8
  s.version = <%= module_name %>::VERSION
9
- s.authors = <%= authors.inspect %>
9
+ s.authors = [<%= author.inspect %>]
10
10
  s.email = <%= email.inspect %>
11
11
  s.homepage = <%= homepage.inspect %>
12
12
  s.summary = <%= summary.inspect %>
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+
@@ -1,20 +1,16 @@
1
1
  module GemRelease
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
 
4
4
  class Version < Template
5
5
  attr_reader :version
6
6
 
7
7
  def initialize(options = {})
8
- super
8
+ super('version.rb', options)
9
9
  @version ||= '0.0.1'
10
10
  end
11
11
 
12
12
  def filename
13
13
  "lib/#{module_path}/version.rb"
14
14
  end
15
-
16
- def template_name
17
- 'version.erb'
18
- end
19
15
  end if defined?(Template)
20
16
  end
@@ -15,11 +15,7 @@ module GemRelease
15
15
 
16
16
  def bump!
17
17
  File.open(filename, 'w+') { |f| f.write(bumped_content) }
18
- force_load!
19
- end
20
-
21
- def force_load!
22
- silence { load(filename) }
18
+ require_version
23
19
  end
24
20
 
25
21
  def new_number
@@ -38,6 +34,15 @@ module GemRelease
38
34
 
39
35
  protected
40
36
 
37
+ def require_version
38
+ $: << 'lib' unless $:.include?('lib')
39
+ require "#{gem_module_path}/version"
40
+ end
41
+
42
+ def force_load!
43
+ silence { load(filename) }
44
+ end
45
+
41
46
  def major(major, minor, patch)
42
47
  "#{major.to_i + 1}.0.0"
43
48
  end
@@ -5,51 +5,82 @@ class Gem::Commands::BootstrapCommand < Gem::Command
5
5
  include GemRelease, Gem::Commands
6
6
  include Helpers, CommandOptions
7
7
 
8
- OPTIONS = { :gemspec => true, :strategy => 'git', :scaffold => false, :github => false }
8
+ DEFAULTS = {
9
+ :gemspec => true,
10
+ :strategy => 'git',
11
+ :scaffold => false,
12
+ :github => false,
13
+ :quiet => false
14
+ }
9
15
 
10
16
  attr_reader :arguments, :usage
11
17
 
12
- def initialize
13
- super 'bootstrap', 'Bootstrap a new gem source repository', OPTIONS
18
+ def initialize(options = {})
19
+ super 'bootstrap', 'Bootstrap a new gem source repository', DEFAULTS.merge(options)
14
20
 
15
21
  option :gemspec, '-g', 'Generate a .gemspec'
16
22
  option :strategy, '-f', 'Strategy for collecting files [glob|git] in .gemspec'
17
23
  option :scaffold, '-s', 'Scaffold lib/[gem_name]/version.rb README test/'
18
24
  option :github, '-h', 'Bootstrap a git repo, create on github and push'
25
+ option :quiet, '-q', 'Do not output status messages'
19
26
  end
20
27
 
21
28
  def execute
22
- write_gemspec if options[:gemspec]
23
29
  write_scaffold if options[:scaffold]
30
+ write_gemspec if options[:gemspec]
24
31
  create_repo if options[:github]
25
32
  end
26
33
 
27
34
  def write_gemspec
28
- GemspecCommand.new.invoke
35
+ GemspecCommand.new(:quiet => quiet?).invoke
29
36
  end
30
37
 
31
38
  def write_scaffold
32
- say 'scaffolding lib/ README test/'
33
- `mkdir lib test`
34
- `touch README`
35
- write_version
36
- write_rakefile
39
+ say 'scaffolding ...' unless quiet?
40
+ create_lib
41
+ create_readme
42
+ create_license
43
+ create_gemfile
44
+ create_test_helper
45
+ create_version
46
+ create_rakefile
47
+ end
48
+
49
+ def create_lib
50
+ `mkdir -p lib test`
51
+ end
52
+
53
+ def create_readme
54
+ `echo "# #{gem_name}" > README.md`
55
+ end
56
+
57
+ def create_license
58
+ Template.new('LICENSE', :year => Time.now.year, :author => user_name, :email => user_email).write
59
+ end
60
+
61
+ def create_gemfile
62
+ Template.new('Gemfile').write
63
+ end
64
+
65
+ def create_test_helper
66
+ Template.new('test/test_helper.rb').write
37
67
  end
38
68
 
39
- def write_version
69
+ def create_version
40
70
  version = Version.new(options)
41
71
  if File.exists?("#{version.filename}")
42
- say "Skipping #{version.filename}: already exists"
72
+ say "Skipping #{version.filename}: already exists" unless quiet?
43
73
  else
44
- say "Creating #{version.filename}"
74
+ say "Creating #{version.filename}" unless quiet?
45
75
  version.write
46
76
  end
47
77
  end
48
78
 
49
- def write_rakefile
79
+ def create_rakefile
50
80
  if File.exists?('Rakefile')
51
- say "Skipping Rakefile: already exists"
81
+ say "Skipping Rakefile: already exists" unless quiet?
52
82
  else
83
+ say "Creating Rakefile" unless quiet?
53
84
  rakefile = <<RAKEFILE
54
85
  require 'rake'
55
86
  require 'rake/testtask'
@@ -1,3 +1,4 @@
1
+ require 'gem_release'
1
2
  require 'rubygems/commands/tag_command'
2
3
  require 'rubygems/commands/release_command'
3
4
 
@@ -7,20 +8,30 @@ class Gem::Commands::BumpCommand < Gem::Command
7
8
 
8
9
  attr_reader :arguments, :usage
9
10
 
10
- OPTIONS = { :version => 'patch', :push => false, :tag => false, :release => false }
11
+ DEFAULTS = {
12
+ :version => 'patch',
13
+ :push => false,
14
+ :tag => false,
15
+ :release => false,
16
+ :commit => true,
17
+ :quiet => false
18
+ }
11
19
 
12
- def initialize
13
- super 'bump', 'Bump the gem version', OPTIONS
20
+ def initialize(options = {})
21
+ super 'bump', 'Bump the gem version', DEFAULTS.merge(options)
14
22
 
15
23
  option :version, '-v', 'Target version: next [major|minor|patch] or a given version number [x.x.x]'
24
+ option :commit, '-c', 'Perform a commit after incrementing gem version'
16
25
  option :push, '-p', 'Push to origin'
17
26
  option :tag, '-t', 'Create a git tag and push --tags to origin'
18
27
  option :release, '-r', 'Build gem from a gemspec and push to rubygems.org'
28
+ option :quiet, '-q', 'Do not output status messages'
19
29
  end
20
30
 
21
31
  def execute
22
- bump
23
- commit
32
+ in_spec_dirs { bump }
33
+
34
+ commit if options[:commit]
24
35
  push if options[:push] || options[:tag]
25
36
  release if options[:release]
26
37
  tag if options[:tag]
@@ -28,19 +39,26 @@ class Gem::Commands::BumpCommand < Gem::Command
28
39
 
29
40
  protected
30
41
 
42
+ def in_spec_dirs
43
+ spec_dirs.each do |dir|
44
+ @version = nil
45
+ Dir.chdir(dir) { yield }
46
+ end
47
+ end
48
+
31
49
  def bump
32
- say "Bumping from #{version.old_number} to version #{version.new_number}"
50
+ say "Bumping #{gem_name} from #{version.old_number} to version #{version.new_number}" unless quiet?
33
51
  version.bump!
34
52
  end
35
53
 
36
54
  def commit
37
- say "Creating commit"
55
+ say "Creating commit" unless quiet?
38
56
  `git add #{version.filename}`
39
57
  `git commit -m "Bump to #{version.new_number}"`
40
58
  end
41
59
 
42
60
  def push
43
- say "Pushing to origin"
61
+ say "Pushing to origin" unless quiet?
44
62
  `git push`
45
63
  end
46
64
 
@@ -55,4 +73,8 @@ class Gem::Commands::BumpCommand < Gem::Command
55
73
  def version
56
74
  @version ||= VersionFile.new(:target => options[:version])
57
75
  end
76
+
77
+ def spec_dirs
78
+ Dir.glob('**/*.gemspec').map { |spec| File.dirname(spec) }
79
+ end
58
80
  end
@@ -2,22 +2,26 @@ class Gem::Commands::GemspecCommand < Gem::Command
2
2
  include GemRelease
3
3
  include Helpers, CommandOptions
4
4
 
5
- OPTIONS = { :strategy => 'git' }
5
+ DEFAULTS = {
6
+ :strategy => 'git',
7
+ :quiet => false
8
+ }
6
9
 
7
10
  attr_reader :arguments, :usage
8
11
 
9
- def initialize
10
- super 'bootstrap', 'Bootstrap a new gem source repository', OPTIONS
12
+ def initialize(options = {})
13
+ super 'bootstrap', 'Bootstrap a new gem source repository', DEFAULTS.merge(options)
11
14
 
12
15
  option :strategy, '-f', 'Strategy for collecting files [glob|git] in .gemspec'
16
+ option :quiet, '-q', 'Do not output status messages'
13
17
  end
14
18
 
15
19
  def execute
16
20
  gemspec = Gemspec.new(options)
17
21
  if gemspec.exists?
18
- say "Skipping #{gemspec.filename}: already exists"
22
+ say "Skipping #{gemspec.filename}: already exists" unless quiet?
19
23
  else
20
- say "Creating #{gemspec.filename}"
24
+ say "Creating #{gemspec.filename}" unless quiet?
21
25
  gemspec.write
22
26
  end
23
27
  end
@@ -6,13 +6,19 @@ class Gem::Commands::ReleaseCommand < Gem::Command
6
6
  include GemRelease, Gem::Commands
7
7
  include Helpers, CommandOptions
8
8
 
9
- OPTIONS = { :tag => false }
9
+ DEFAULTS = {
10
+ :tag => false,
11
+ :quiet => false
12
+ }
10
13
 
11
14
  attr_reader :arguments, :usage
12
15
 
13
- def initialize
14
- super 'release', 'Build gem from a gemspec and push to rubygems.org'
15
- option :tag, '-t', 'Create a git tag and push --tags to origin'
16
+ def initialize(options = {})
17
+ super 'release', 'Build gem from a gemspec and push to rubygems.org', DEFAULTS.merge(options)
18
+
19
+ option :tag, '-t', 'Create a git tag and push --tags to origin'
20
+ option :quiet, '-q', 'Do not output status messages'
21
+
16
22
  @arguments = "gemspec - optional gemspec file name, will use the first *.gemspec if not specified"
17
23
  @usage = "#{program_name} [gemspec]"
18
24
  end
@@ -36,8 +42,8 @@ class Gem::Commands::ReleaseCommand < Gem::Command
36
42
  end
37
43
 
38
44
  def remove
45
+ say "Deleting left over gem file #{gem_filename}" unless quiet?
39
46
  `rm #{gem_filename}`
40
- say "Deleting left over gem file #{gem_filename}"
41
47
  end
42
48
 
43
49
  def tag
@@ -2,10 +2,16 @@ class Gem::Commands::TagCommand < Gem::Command
2
2
  include GemRelease
3
3
  include Helpers, CommandOptions
4
4
 
5
+ DEFAULTS = {
6
+ :quiet => false
7
+ }
8
+
5
9
  attr_reader :arguments, :usage
6
10
 
7
- def initialize
8
- super 'tag', 'Create a git tag and push --tags to origin'
11
+ def initialize(options = {})
12
+ super 'tag', 'Create a git tag and push --tags to origin', DEFAULTS.merge(options)
13
+
14
+ option :quiet, '-q', 'Do not output status messages'
9
15
  end
10
16
 
11
17
  def execute
@@ -16,12 +22,12 @@ class Gem::Commands::TagCommand < Gem::Command
16
22
  protected
17
23
 
18
24
  def tag
19
- say "Creating git tag #{tag_name}"
25
+ say "Creating git tag #{tag_name}" unless quiet?
20
26
  `git tag -am 'tag #{tag_name}' #{tag_name}`
21
27
  end
22
28
 
23
29
  def push
24
- say "Pushing --tags to origin git repository"
30
+ say "Pushing --tags to origin git repository" unless quiet?
25
31
  `git push --tags origin`
26
32
  end
27
33
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-release
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
5
- prerelease: false
4
+ hash: 61
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 16
10
- version: 0.0.16
9
+ - 17
10
+ version: 0.0.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-05 00:00:00 +01:00
18
+ date: 2011-07-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,9 +65,13 @@ files:
65
65
  - lib/gem_release/command_options.rb
66
66
  - lib/gem_release/gemspec.rb
67
67
  - lib/gem_release/helpers.rb
68
+ - lib/gem_release/license.rb
68
69
  - lib/gem_release/template.rb
69
- - lib/gem_release/templates/gemspec.erb
70
- - lib/gem_release/templates/version.erb
70
+ - lib/gem_release/templates/Gemfile
71
+ - lib/gem_release/templates/LICENSE
72
+ - lib/gem_release/templates/gemspec
73
+ - lib/gem_release/templates/test/test_helper.rb
74
+ - lib/gem_release/templates/version.rb
71
75
  - lib/gem_release/version.rb
72
76
  - lib/gem_release/version_file.rb
73
77
  - lib/rubygems/commands/bootstrap_command.rb
@@ -108,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  requirements: []
109
113
 
110
114
  rubyforge_project: "[none]"
111
- rubygems_version: 1.3.7
115
+ rubygems_version: 1.6.2
112
116
  signing_key:
113
117
  specification_version: 3
114
118
  summary: Release your ruby gems with ease