gem-this 0.2.1 → 0.3.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.
- data/Rakefile +23 -16
- data/Rakefile.erb +45 -24
- data/bin/gem-this +1 -1
- data/lib/gem_this.rb +50 -12
- data/lib/rubygems_plugin.rb +1 -1
- metadata +34 -5
data/Rakefile
CHANGED
@@ -2,8 +2,13 @@ require "rubygems"
|
|
2
2
|
require "rake/gempackagetask"
|
3
3
|
require "rake/rdoctask"
|
4
4
|
|
5
|
-
task :default => :
|
6
|
-
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
require "rake/testtask"
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs = [File.expand_path("lib"), "test"]
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
11
|
+
t.verbose = true
|
7
12
|
end
|
8
13
|
|
9
14
|
# This builds the actual gem. For details of what all these options
|
@@ -12,10 +17,10 @@ end
|
|
12
17
|
# http://rubygems.org/read/chapter/20
|
13
18
|
#
|
14
19
|
spec = Gem::Specification.new do |s|
|
15
|
-
|
20
|
+
|
16
21
|
# Change these as appropriate
|
17
22
|
s.name = "gem-this"
|
18
|
-
s.version = "0.
|
23
|
+
s.version = "0.3.0"
|
19
24
|
s.summary = "Make existing code into a gem, without any fuss."
|
20
25
|
s.author = "James Adam"
|
21
26
|
s.email = "james@lazyatom.com"
|
@@ -29,28 +34,30 @@ spec = Gem::Specification.new do |s|
|
|
29
34
|
s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin,lib}/**/*")
|
30
35
|
s.executables = FileList["bin/**"].map { |f| File.basename(f) }
|
31
36
|
s.require_paths = ["bin", "lib"]
|
32
|
-
|
37
|
+
|
33
38
|
# If you want to depend on other gems, add them here, along with any
|
34
39
|
# relevant versions
|
35
40
|
# s.add_dependency("some_other_gem", "~> 0.1.0")
|
36
|
-
|
41
|
+
|
37
42
|
# If your tests use any gems, include them here
|
38
|
-
|
43
|
+
s.add_development_dependency("shoulda")
|
44
|
+
s.add_development_dependency("rspec")
|
45
|
+
s.add_development_dependency("cucumber")
|
39
46
|
|
40
47
|
# If you want to publish automatically to rubyforge, you'll may need
|
41
48
|
# to tweak this, and the publishing task below too.
|
42
49
|
s.rubyforge_project = "gem-this"
|
43
|
-
|
50
|
+
|
44
51
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3")
|
45
52
|
end
|
46
53
|
|
47
|
-
# This task actually builds the gem. We also regenerate a static
|
54
|
+
# This task actually builds the gem. We also regenerate a static
|
48
55
|
# .gemspec file, which is useful if something (i.e. GitHub) will
|
49
56
|
# be automatically building a gem for this project. If you're not
|
50
57
|
# using GitHub, edit as appropriate.
|
51
58
|
Rake::GemPackageTask.new(spec) do |pkg|
|
52
59
|
pkg.gem_spec = spec
|
53
|
-
|
60
|
+
|
54
61
|
# Generate the gemspec file for github.
|
55
62
|
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
56
63
|
File.open(file, "w") {|f| f << spec.to_ruby }
|
@@ -68,7 +75,7 @@ task :clean => [:clobber_rdoc, :clobber_package] do
|
|
68
75
|
rm "#{spec.name}.gemspec"
|
69
76
|
end
|
70
77
|
|
71
|
-
# If you want to publish to RubyForge automatically, here's a simple
|
78
|
+
# If you want to publish to RubyForge automatically, here's a simple
|
72
79
|
# task to help do that. If you don't, just get rid of this.
|
73
80
|
# Be sure to set up your Rubyforge account details with the Rubyforge
|
74
81
|
# gem; you'll need to run `rubyforge setup` and `rubyforge config` at
|
@@ -76,10 +83,10 @@ end
|
|
76
83
|
begin
|
77
84
|
require "rake/contrib/sshpublisher"
|
78
85
|
namespace :rubyforge do
|
79
|
-
|
86
|
+
|
80
87
|
desc "Release gem and RDoc documentation to RubyForge"
|
81
88
|
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
82
|
-
|
89
|
+
|
83
90
|
namespace :release do
|
84
91
|
desc "Release a new version of this gem"
|
85
92
|
task :gem => [:package] do
|
@@ -92,17 +99,17 @@ begin
|
|
92
99
|
puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..."
|
93
100
|
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
|
94
101
|
end
|
95
|
-
|
102
|
+
|
96
103
|
desc "Publish RDoc to RubyForge."
|
97
104
|
task :docs => [:rdoc] do
|
98
105
|
config = YAML.load(
|
99
106
|
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
100
107
|
)
|
101
|
-
|
108
|
+
|
102
109
|
host = "#{config['username']}@rubyforge.org"
|
103
110
|
remote_dir = "/var/www/gforge-projects/gem-this/" # Should be the same as the rubyforge project name
|
104
111
|
local_dir = 'rdoc'
|
105
|
-
|
112
|
+
|
106
113
|
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
107
114
|
end
|
108
115
|
end
|
data/Rakefile.erb
CHANGED
@@ -3,8 +3,6 @@ require "rake/gempackagetask"
|
|
3
3
|
require "rake/rdoctask"
|
4
4
|
|
5
5
|
<% if using_rspec? %>
|
6
|
-
task :default => :spec
|
7
|
-
|
8
6
|
require "spec"
|
9
7
|
require "spec/rake/spectask"
|
10
8
|
Spec::Rake::SpecTask.new do |t|
|
@@ -12,18 +10,28 @@ Spec::Rake::SpecTask.new do |t|
|
|
12
10
|
t.libs = ["spec"]
|
13
11
|
end
|
14
12
|
<% elsif using_test_unit? %>
|
15
|
-
task :default => :test
|
16
|
-
|
17
13
|
require "rake/testtask"
|
18
14
|
Rake::TestTask.new do |t|
|
19
15
|
t.libs << "test"
|
20
16
|
t.test_files = FileList["test/**/*_test.rb"]
|
21
17
|
t.verbose = true
|
22
18
|
end
|
23
|
-
<%
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<% if using_cucumber? %>
|
22
|
+
require 'cucumber'
|
23
|
+
require 'cucumber/rake/task'
|
24
|
+
Cucumber::Rake::Task.new('features') do |t|
|
25
|
+
t.cucumber_opts = %w{--format pretty}
|
26
|
+
end
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<% if default_tasks.empty? %>
|
24
30
|
task :default => :package do
|
25
31
|
puts "Don't forget to write some tests!"
|
26
32
|
end
|
33
|
+
<% else %>
|
34
|
+
task :default => <%= default_tasks.inspect %>
|
27
35
|
<% end %>
|
28
36
|
|
29
37
|
# This builds the actual gem. For details of what all these options
|
@@ -32,7 +40,7 @@ end
|
|
32
40
|
# http://rubygems.org/read/chapter/20
|
33
41
|
#
|
34
42
|
spec = Gem::Specification.new do |s|
|
35
|
-
|
43
|
+
|
36
44
|
# Change these as appropriate
|
37
45
|
s.name = "<%= name %>"
|
38
46
|
s.version = "0.1.0"
|
@@ -47,7 +55,7 @@ spec = Gem::Specification.new do |s|
|
|
47
55
|
s.rdoc_options = %w(--main <%= readme %>)
|
48
56
|
|
49
57
|
# Add any extra files to include in the gem
|
50
|
-
<% else %>
|
58
|
+
<% else %>
|
51
59
|
# You should probably have a README of some kind. Change the filename
|
52
60
|
# as appropriate
|
53
61
|
# s.extra_rdoc_files = %w(README)
|
@@ -55,21 +63,34 @@ spec = Gem::Specification.new do |s|
|
|
55
63
|
|
56
64
|
# Add any extra files to include in the gem (like your README)
|
57
65
|
<% end %>
|
58
|
-
s.files = %w(<%= files_in_root %>) + Dir.glob("{<%=
|
66
|
+
s.files = %w(<%= files_in_root %>) + Dir.glob("{<%= dirs_to_include_glob %>}")
|
59
67
|
<% if has_executables? %>
|
60
68
|
s.executables = FileList["bin/**"].map { |f| File.basename(f) }
|
61
|
-
<% end %>
|
69
|
+
<% end %>
|
70
|
+
<% if has_lib_directory? %>
|
62
71
|
s.require_paths = ["lib"]
|
63
|
-
|
72
|
+
<% else %>
|
73
|
+
|
74
|
+
# You need to put your code in a directory which can then be added to
|
75
|
+
# the $LOAD_PATH by rubygems. Typically this is lib, but you don't seem
|
76
|
+
# to have that directory. You'll need to set the line below to whatever
|
77
|
+
# directory your code is in. Rubygems is going to assume lib if you leave
|
78
|
+
# this blank.
|
79
|
+
#
|
80
|
+
# s.require_paths = ["lib"]
|
81
|
+
<% end %>
|
82
|
+
|
64
83
|
# If you want to depend on other gems, add them here, along with any
|
65
84
|
# relevant versions
|
66
85
|
# s.add_dependency("some_other_gem", "~> 0.1.0")
|
67
|
-
|
68
|
-
<% if using_rspec? %>
|
69
|
-
s.add_development_dependency("rspec") # add any other gems for testing/development
|
70
|
-
<% else %>
|
86
|
+
|
71
87
|
# If your tests use any gems, include them here
|
72
|
-
|
88
|
+
<% if development_dependencies.any? %>
|
89
|
+
<% development_dependencies.each do |dependency| %>
|
90
|
+
s.add_development_dependency("<%= dependency %>")
|
91
|
+
<% end %>
|
92
|
+
<% else %>
|
93
|
+
# s.add_development_dependency("mocha") # for example
|
73
94
|
<% end %>
|
74
95
|
|
75
96
|
# If you want to publish automatically to rubyforge, you'll may need
|
@@ -77,13 +98,13 @@ spec = Gem::Specification.new do |s|
|
|
77
98
|
s.rubyforge_project = "<%= name %>"
|
78
99
|
end
|
79
100
|
|
80
|
-
# This task actually builds the gem. We also regenerate a static
|
101
|
+
# This task actually builds the gem. We also regenerate a static
|
81
102
|
# .gemspec file, which is useful if something (i.e. GitHub) will
|
82
103
|
# be automatically building a gem for this project. If you're not
|
83
104
|
# using GitHub, edit as appropriate.
|
84
105
|
Rake::GemPackageTask.new(spec) do |pkg|
|
85
106
|
pkg.gem_spec = spec
|
86
|
-
|
107
|
+
|
87
108
|
# Generate the gemspec file for github.
|
88
109
|
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
89
110
|
File.open(file, "w") {|f| f << spec.to_ruby }
|
@@ -101,7 +122,7 @@ task :clean => [:clobber_rdoc, :clobber_package] do
|
|
101
122
|
rm "#{spec.name}.gemspec"
|
102
123
|
end
|
103
124
|
|
104
|
-
# If you want to publish to RubyForge automatically, here's a simple
|
125
|
+
# If you want to publish to RubyForge automatically, here's a simple
|
105
126
|
# task to help do that. If you don't, just get rid of this.
|
106
127
|
# Be sure to set up your Rubyforge account details with the Rubyforge
|
107
128
|
# gem; you'll need to run `rubyforge setup` and `rubyforge config` at
|
@@ -109,10 +130,10 @@ end
|
|
109
130
|
begin
|
110
131
|
require "rake/contrib/sshpublisher"
|
111
132
|
namespace :rubyforge do
|
112
|
-
|
133
|
+
|
113
134
|
desc "Release gem and RDoc documentation to RubyForge"
|
114
135
|
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
115
|
-
|
136
|
+
|
116
137
|
namespace :release do
|
117
138
|
desc "Release a new version of this gem"
|
118
139
|
task :gem => [:package] do
|
@@ -125,21 +146,21 @@ begin
|
|
125
146
|
puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..."
|
126
147
|
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
|
127
148
|
end
|
128
|
-
|
149
|
+
|
129
150
|
desc "Publish RDoc to RubyForge."
|
130
151
|
task :docs => [:rdoc] do
|
131
152
|
config = YAML.load(
|
132
153
|
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
133
154
|
)
|
134
|
-
|
155
|
+
|
135
156
|
host = "#{config['username']}@rubyforge.org"
|
136
157
|
remote_dir = "/var/www/gforge-projects/<%= name %>/" # Should be the same as the rubyforge project name
|
137
158
|
local_dir = 'rdoc'
|
138
|
-
|
159
|
+
|
139
160
|
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
140
161
|
end
|
141
162
|
end
|
142
163
|
end
|
143
164
|
rescue LoadError
|
144
165
|
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
145
|
-
end
|
166
|
+
end
|
data/bin/gem-this
CHANGED
data/lib/gem_this.rb
CHANGED
@@ -4,14 +4,16 @@ require 'etc'
|
|
4
4
|
class GemThis
|
5
5
|
SUMMARY = "Creates a Rakefile suitable for turning the current project into a gem."
|
6
6
|
DEBUG_MESSAGE = "debug, only prints out the generated Rakefile."
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :name, :debug
|
9
|
-
|
10
|
-
def initialize(name,
|
9
|
+
|
10
|
+
def initialize(name, options={})
|
11
11
|
@name = name
|
12
|
-
|
12
|
+
options = {:default => false, :silent => false}.update(options)
|
13
|
+
@debug = options[:debug]
|
14
|
+
@silent = options[:silent]
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def create_rakefile
|
16
18
|
template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
|
17
19
|
rakefile = template.result(binding)
|
@@ -20,18 +22,26 @@ class GemThis
|
|
20
22
|
puts rakefile
|
21
23
|
else
|
22
24
|
if File.exist?('Rakefile')
|
23
|
-
|
25
|
+
log "Appended to existing Rakefile"
|
24
26
|
File.open('Rakefile', 'a') { |f| 2.times { f.puts }; f.write rakefile }
|
25
27
|
else
|
26
|
-
|
28
|
+
log "Writing new Rakefile"
|
27
29
|
File.open('Rakefile', 'w') { |f| f.write rakefile }
|
28
30
|
end
|
29
31
|
add_to_gitignore if using_git?
|
30
32
|
end
|
33
|
+
unless has_lib_directory?
|
34
|
+
log "You don't see to have a lib directory - please edit the Rakefile to set where your code is."
|
35
|
+
false
|
36
|
+
end
|
31
37
|
end
|
32
|
-
|
38
|
+
|
33
39
|
private
|
34
|
-
|
40
|
+
|
41
|
+
def log(message)
|
42
|
+
puts(message) unless @silent
|
43
|
+
end
|
44
|
+
|
35
45
|
def author_name
|
36
46
|
Etc.getpwnam(ENV['USER']).gecos rescue ENV['USER'] # for Windows
|
37
47
|
end
|
@@ -48,6 +58,10 @@ class GemThis
|
|
48
58
|
File.directory?('spec')
|
49
59
|
end
|
50
60
|
|
61
|
+
def using_cucumber?
|
62
|
+
File.directory?('features')
|
63
|
+
end
|
64
|
+
|
51
65
|
def using_test_unit?
|
52
66
|
File.directory?('test')
|
53
67
|
end
|
@@ -56,8 +70,17 @@ class GemThis
|
|
56
70
|
File.directory?('bin')
|
57
71
|
end
|
58
72
|
|
59
|
-
def
|
60
|
-
|
73
|
+
def has_lib_directory?
|
74
|
+
File.directory?("lib")
|
75
|
+
end
|
76
|
+
|
77
|
+
def dirs_to_include_glob
|
78
|
+
dirs = %w(bin test spec lib).select { |d| File.directory?(d) }
|
79
|
+
if dirs.any?
|
80
|
+
dirs.join(",") + "/**/*"
|
81
|
+
else
|
82
|
+
"**/*"
|
83
|
+
end
|
61
84
|
end
|
62
85
|
|
63
86
|
def readme
|
@@ -72,10 +95,25 @@ class GemThis
|
|
72
95
|
File.exist?(".git")
|
73
96
|
end
|
74
97
|
|
98
|
+
def default_tasks
|
99
|
+
tasks = []
|
100
|
+
tasks << "test" if using_test_unit?
|
101
|
+
tasks << "spec" if using_rspec?
|
102
|
+
tasks << "features" if using_cucumber?
|
103
|
+
tasks
|
104
|
+
end
|
105
|
+
|
106
|
+
def development_dependencies
|
107
|
+
deps = []
|
108
|
+
deps << "rspec" if using_rspec?
|
109
|
+
deps << "cucumber" if using_cucumber?
|
110
|
+
deps
|
111
|
+
end
|
112
|
+
|
75
113
|
def add_to_gitignore
|
76
114
|
return unless File.exist?(".gitignore")
|
77
115
|
ignores = File.readlines(".gitignore")
|
78
116
|
ignores += ["pkg", "rdoc"]
|
79
117
|
File.open(".gitignore", "w") { |f| f.write ignores.map { |l| l.strip }.uniq.join("\n") }
|
80
118
|
end
|
81
|
-
end
|
119
|
+
end
|
data/lib/rubygems_plugin.rb
CHANGED
@@ -15,7 +15,7 @@ class Gem::Commands::ThisCommand < Gem::Command
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute
|
18
|
-
GemThis.new(options[:args].first || File.basename(Dir.pwd), options
|
18
|
+
GemThis.new(options[:args].first || File.basename(Dir.pwd), options).create_rakefile
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-this
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Adam
|
@@ -9,10 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-22 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
16
45
|
description:
|
17
46
|
email: james@lazyatom.com
|
18
47
|
executables:
|
@@ -53,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
82
|
requirements: []
|
54
83
|
|
55
84
|
rubyforge_project: gem-this
|
56
|
-
rubygems_version: 1.3.
|
85
|
+
rubygems_version: 1.3.5
|
57
86
|
signing_key:
|
58
87
|
specification_version: 3
|
59
88
|
summary: Make existing code into a gem, without any fuss.
|