gem_init 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.default +3 -0
- data/MIT-LICENSE +19 -0
- data/README.md +89 -0
- data/Rakefile +29 -0
- data/bin/gem_init +4 -0
- data/gem_init.gemspec +17 -0
- data/lib/gem_init.rb +2 -0
- data/lib/gem_init/app.rb +116 -0
- data/lib/gem_init/templates/Gemfile.default.erb +3 -0
- data/lib/gem_init/templates/MIT-LICENSE.erb +18 -0
- data/lib/gem_init/templates/README.md.erb +30 -0
- data/lib/gem_init/templates/Rakefile.erb +18 -0
- data/lib/gem_init/templates/gemspec.erb +16 -0
- data/lib/gem_init/templates/gitignore.erb +5 -0
- data/lib/gem_init/templates/module.rb.erb +1 -0
- data/lib/gem_init/templates/module_test.rb.erb +7 -0
- data/lib/gem_init/templates/test_helper.rb.erb +11 -0
- data/lib/gem_init/templates/version.rb.erb +9 -0
- data/lib/gem_init/version.rb +9 -0
- metadata +82 -0
data/Gemfile.default
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Norman Clarke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Gem Init
|
2
|
+
|
3
|
+
This is the code I use to set up a new Ruby Gem.
|
4
|
+
|
5
|
+
Github and Rubygems.org make it ridiculously easy to share your code using Gems.
|
6
|
+
Sometimes I have something small and useful I'd like to make a gem, but I'm too
|
7
|
+
lazy to set up all the packaging boilerplate, and I prefer not to introduce
|
8
|
+
tools like Jewler or Hoe just to manage a gemspec, which is a trivially easy
|
9
|
+
file to maintain. Setting up a new gem is boring, so I spent a couple hours
|
10
|
+
putting this together as a reusable gem. If you like it, please feel free to use
|
11
|
+
it for whatever purpose you choose. Bug fixes, and patches are of course
|
12
|
+
welcome.
|
13
|
+
|
14
|
+
## Using it:
|
15
|
+
|
16
|
+
gem install gem_init
|
17
|
+
gem_init hello_world
|
18
|
+
|
19
|
+
A brief summary of some of the quirkiness is below:
|
20
|
+
|
21
|
+
## Your name, email and Github user name
|
22
|
+
|
23
|
+
These are read from your `~/.gitconfig` if available and used to populate some
|
24
|
+
basic info in the gemspec.
|
25
|
+
|
26
|
+
## MIT-LICENSE
|
27
|
+
|
28
|
+
This is the license I almost always use for my open source work, so it's the
|
29
|
+
default.
|
30
|
+
|
31
|
+
## Gemfile.default
|
32
|
+
|
33
|
+
I prefer not to check my Gemfiles into git, because I usually tweak it a lot
|
34
|
+
when testing against lots of different versions of my dependencies. So I usually
|
35
|
+
just add a Gemfile.default with something that should work, and copy that to
|
36
|
+
Gemfile before working.
|
37
|
+
|
38
|
+
The only thing added by default to the Gemfile is your generated library itself,
|
39
|
+
which is an easy way to avoid messing around with the `LOAD_PATH` in your test
|
40
|
+
setup.
|
41
|
+
|
42
|
+
I am assuming Bundler version 1.0.x, which you can currently get by doing
|
43
|
+
|
44
|
+
gem install bundler --pre
|
45
|
+
|
46
|
+
But by the time you're reading this, it may already be the current stable
|
47
|
+
release.
|
48
|
+
|
49
|
+
## test_helper.rb
|
50
|
+
|
51
|
+
This just adds a `test` method to the `Module` class, so you can write
|
52
|
+
declarative tests:
|
53
|
+
|
54
|
+
test "something should do something" do
|
55
|
+
assert_equal foo, bar
|
56
|
+
end
|
57
|
+
|
58
|
+
Having this as a class method in `Module` means you can write your unit tests in
|
59
|
+
either modules or classes. Being able to group related tests in modules and give
|
60
|
+
them declarative names for me is "good enough" to make up for Test::Unit's
|
61
|
+
ugliness, and I like the fact that it's just plain old Ruby.
|
62
|
+
|
63
|
+
I tend to do this rather than use a bigger test framework, because it introduces
|
64
|
+
less dependencies and makes it very easy for people to just check out my gem and
|
65
|
+
run my tests with the minimum of effort.
|
66
|
+
|
67
|
+
## *.gemspec
|
68
|
+
|
69
|
+
Rather than manually specifying everything, I just pull the files I want to add
|
70
|
+
to the gem out of the list of files added to Git. This works fine most of the
|
71
|
+
time, with the only caveat being that you need to have your stuff in Git before
|
72
|
+
building your gem, or using the directory as a gem via Bundler.
|
73
|
+
|
74
|
+
## Rakefile
|
75
|
+
|
76
|
+
This adds a soft dependency on [Yard](http://yardoc.org/); the task is added only if you
|
77
|
+
have it installed.
|
78
|
+
|
79
|
+
Otherwise, by default a `gem` method is added to package your gem, and a `clean`
|
80
|
+
method is there to tidy up your repository.
|
81
|
+
|
82
|
+
## .gitignore
|
83
|
+
|
84
|
+
By default, I ignore Gemfile, Gemfile.lock, pkg and doc directories. Obviously
|
85
|
+
you can and should change this to whatever makes sense for you.
|
86
|
+
|
87
|
+
## README.md
|
88
|
+
|
89
|
+
I like to use Markdown for my README files, as it plays nicely with Yard.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
require "rake/clean"
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
CLEAN << "pkg" << "doc" << "coverage" << ".yardoc"
|
9
|
+
Rake::GemPackageTask.new(eval(File.read("gem_init.gemspec"))) { |pkg| }
|
10
|
+
Rake::TestTask.new(:test) { |t| t.pattern = "test/**/*_test.rb" }
|
11
|
+
|
12
|
+
begin
|
13
|
+
require "yard"
|
14
|
+
YARD::Rake::YardocTask.new do |t|
|
15
|
+
t.options = ["--output-dir=doc"]
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
require "rcov/rcovtask"
|
22
|
+
Rcov::RcovTask.new do |r|
|
23
|
+
r.test_files = FileList["test/**/*_test.rb"]
|
24
|
+
r.verbose = true
|
25
|
+
r.rcov_opts << "--exclude gems/*"
|
26
|
+
end
|
27
|
+
rescue LoadError
|
28
|
+
end
|
29
|
+
|
data/bin/gem_init
ADDED
data/gem_init.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("../lib/gem_init/version", __FILE__)
|
2
|
+
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = "gem_init"
|
5
|
+
s.rubyforge_project = "[none]"
|
6
|
+
s.version = GemInit::Version::STRING
|
7
|
+
s.authors = "Norman Clarke"
|
8
|
+
s.email = "norman@njclarke.com"
|
9
|
+
s.homepage = "http://github.com/norman/gem_init"
|
10
|
+
s.summary = "My new gem boilerplate."
|
11
|
+
s.description = "This is the code I use to set up a new Ruby Gem."
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.test_files = Dir.glob "test/**/*_test.rb"
|
15
|
+
s.files = `git ls-files`.split("\n").reject {|f| f =~ /^\./}
|
16
|
+
s.executables = ["gem_init"]
|
17
|
+
end
|
data/lib/gem_init.rb
ADDED
data/lib/gem_init/app.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "shellwords"
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
module GemInit
|
6
|
+
class App
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
attr :gem_name
|
10
|
+
attr :module_name
|
11
|
+
attr :templates
|
12
|
+
|
13
|
+
DEFAULT_GIT_CONFIG = {
|
14
|
+
:user => {
|
15
|
+
:name => "YOUR NAME",
|
16
|
+
:email => "YOUR EMAIL",
|
17
|
+
},
|
18
|
+
:github => {
|
19
|
+
:name => "your_github_user_name"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
def initialize(gem_name)
|
24
|
+
@gem_name = gem_name.downcase
|
25
|
+
@templates = File.expand_path("../templates", __FILE__)
|
26
|
+
end
|
27
|
+
|
28
|
+
def main
|
29
|
+
if File.exists?(gem_name)
|
30
|
+
raise "Directory '#{gem_name}' already exists, bailing out."
|
31
|
+
end
|
32
|
+
mkdir_p module_lib_dir
|
33
|
+
mkdir_p test_dir
|
34
|
+
write_template(lib_dir, "module.rb", "#{gem_name}.rb")
|
35
|
+
write_template(module_lib_dir, "version.rb")
|
36
|
+
write_template(test_dir, "test_helper.rb")
|
37
|
+
write_template(test_dir, "module_test.rb", "#{gem_name}_test.rb")
|
38
|
+
write_template(gem_name, "gemspec", "#{gem_name}.gemspec")
|
39
|
+
write_template(gem_name, "Gemfile.default")
|
40
|
+
write_template(gem_name, "Gemfile.default", "Gemfile")
|
41
|
+
write_template(gem_name, "Rakefile")
|
42
|
+
write_template(gem_name, "MIT-LICENSE")
|
43
|
+
write_template(gem_name, "README.md")
|
44
|
+
write_template(gem_name, "gitignore", ".gitignore")
|
45
|
+
`git init #{gem_name.shellescape}`
|
46
|
+
end
|
47
|
+
|
48
|
+
def author
|
49
|
+
@author ||= git_config[:user][:name]
|
50
|
+
end
|
51
|
+
|
52
|
+
def email
|
53
|
+
@email ||= git_config[:user][:email]
|
54
|
+
end
|
55
|
+
|
56
|
+
def github_user
|
57
|
+
@github_user ||= git_config[:github][:user]
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def git_config
|
63
|
+
@git_config ||= read_git_config || DEFAULT_GIT_CONFIG
|
64
|
+
end
|
65
|
+
|
66
|
+
def read_git_config
|
67
|
+
begin
|
68
|
+
config = {}
|
69
|
+
key = nil
|
70
|
+
File.read(File.expand_path("~/.gitconfig")).split("\n").each do |line|
|
71
|
+
if line =~ /\A\s?+\[([\w]*)\]\s?+\z/
|
72
|
+
key = $1.strip.to_sym
|
73
|
+
config[key] = {}
|
74
|
+
elsif line =~ /\A\s?+(.*)\s?+=\s?+(.*)\s?+\Z/
|
75
|
+
config[key][$1.strip.to_sym] = $2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
# Be a tad paranoid and make it harder to accidentally reveal this
|
79
|
+
config[:github][:token] = nil
|
80
|
+
config
|
81
|
+
rescue Errno::ENOENT
|
82
|
+
warn "Could not read your ~/.gitconfig, using silly defaults."
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def module_name
|
87
|
+
@module_name ||= gem_name.gsub(/\b[\w]|_[\w]/) {|s| s.upcase}.gsub("_", "")
|
88
|
+
end
|
89
|
+
|
90
|
+
def lib_dir
|
91
|
+
@lib_dir = File.join(gem_name, "lib")
|
92
|
+
end
|
93
|
+
|
94
|
+
def module_lib_dir
|
95
|
+
@module_lib_dir = File.join(lib_dir, gem_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_dir
|
99
|
+
@test_dir = File.join(gem_name, "test")
|
100
|
+
end
|
101
|
+
|
102
|
+
def write_template(dir, template_name, output_name = nil)
|
103
|
+
output_name ||= template_name
|
104
|
+
File.open(File.join(dir, output_name), "w") do |file|
|
105
|
+
file.write(read_template(template_name))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def read_template(file_name)
|
110
|
+
file = File.join(templates, "#{file_name}.erb")
|
111
|
+
File.open(file, "r") do |f|
|
112
|
+
ERB.new(f.read).result(binding)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) <%= Time.now.year %> <%= author %>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# <%= module_name %>
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
gem install <%= gem_name %>
|
6
|
+
|
7
|
+
## Author
|
8
|
+
|
9
|
+
<%= author %> (<%= email %>)
|
10
|
+
|
11
|
+
## License
|
12
|
+
|
13
|
+
Copyright (c) <%= Time.now.year %> <%= author %>
|
14
|
+
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
16
|
+
this software and associated documentation files (the "Software"), to deal in
|
17
|
+
the Software without restriction, including without limitation the rights to
|
18
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
19
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
20
|
+
subject to the following conditions:
|
21
|
+
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
23
|
+
copies or substantial portions of the Software.
|
24
|
+
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
27
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
28
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
29
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
30
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
require "rake/clean"
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
CLEAN << "pkg" << "doc" << "coverage" << ".yardoc"
|
9
|
+
Rake::GemPackageTask.new(eval(File.read("<%= @gem_name %>.gemspec"))) { |pkg| }
|
10
|
+
Rake::TestTask.new(:test) { |t| t.pattern = "test/**/*_test.rb" }
|
11
|
+
|
12
|
+
begin
|
13
|
+
require "yard"
|
14
|
+
YARD::Rake::YardocTask.new do |t|
|
15
|
+
t.options = ["--output-dir=doc"]
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("../lib/<%= gem_name %>/version", __FILE__)
|
2
|
+
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = "<%= gem_name %>"
|
5
|
+
s.rubyforge_project = "[none]"
|
6
|
+
s.version = <%= @module_name %>::Version::STRING
|
7
|
+
s.authors = "<%= author %>"
|
8
|
+
s.email = "<%= email %>"
|
9
|
+
s.homepage = "http://github.com/<%= github_user %>/<%= gem_name %>"
|
10
|
+
s.summary = ""
|
11
|
+
s.description = ""
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.test_files = Dir.glob "test/**/*_test.rb"
|
15
|
+
s.files = `git ls-files`.split("\n").reject {|f| f =~ /^\./}
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "<%= gem_name %>/version"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "test/unit"
|
4
|
+
require "<%= gem_name %>"
|
5
|
+
|
6
|
+
# Allow declarative test definitions inside modules.
|
7
|
+
class Module
|
8
|
+
def test(name, &block)
|
9
|
+
define_method("test_#{name.gsub(/[^a-z0-9]/i, "_")}".to_sym, &block)
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem_init
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Norman Clarke
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-16 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: This is the code I use to set up a new Ruby Gem.
|
22
|
+
email: norman@njclarke.com
|
23
|
+
executables:
|
24
|
+
- gem_init
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- Gemfile.default
|
31
|
+
- MIT-LICENSE
|
32
|
+
- README.md
|
33
|
+
- Rakefile
|
34
|
+
- bin/gem_init
|
35
|
+
- gem_init.gemspec
|
36
|
+
- lib/gem_init.rb
|
37
|
+
- lib/gem_init/app.rb
|
38
|
+
- lib/gem_init/templates/Gemfile.default.erb
|
39
|
+
- lib/gem_init/templates/MIT-LICENSE.erb
|
40
|
+
- lib/gem_init/templates/README.md.erb
|
41
|
+
- lib/gem_init/templates/Rakefile.erb
|
42
|
+
- lib/gem_init/templates/gemspec.erb
|
43
|
+
- lib/gem_init/templates/gitignore.erb
|
44
|
+
- lib/gem_init/templates/module.rb.erb
|
45
|
+
- lib/gem_init/templates/module_test.rb.erb
|
46
|
+
- lib/gem_init/templates/test_helper.rb.erb
|
47
|
+
- lib/gem_init/templates/version.rb.erb
|
48
|
+
- lib/gem_init/version.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/norman/gem_init
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: "[none]"
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: My new gem boilerplate.
|
81
|
+
test_files: []
|
82
|
+
|