simple-gem 0.4.1

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.
@@ -0,0 +1,59 @@
1
+ = SimpleGem
2
+
3
+ == Description
4
+
5
+ Creating RubyGems is fun work, but dealing with the complexity of hoe / bones / newgem is not (for me, at least). SimpleGem is a way to quickly create a gem structure with the bare minimum needed to build and deploy.
6
+
7
+ == Installation
8
+
9
+ Ideally:
10
+
11
+ sudo gem install reagent-simple-gem --source=http://gems.github.com
12
+
13
+ But GitHub doesn't seem to consistently build gems, so use this as a fallback:
14
+
15
+ $ git clone git://github.com/reagent/simple-gem.git
16
+ $ cd simple-gem
17
+ $ rake gem
18
+ $ sudo gem install pkg/simple-gem-x.x.x.gem
19
+
20
+ == Usage
21
+
22
+ $ simple-gem my-gem
23
+
24
+ This will create a gem structure under the 'my-gem' directory. The command is pretty forgiving with the name you supply, it will automatically transform anything that is camelcased into something more ruby-like.
25
+
26
+ After generating your gem, go ahead and add information about your gem to both the <tt>Rakefile</tt> and <tt>README.rdoc</tt> files. The default version number is "0.1.0", but if you want to change that, take a look at <tt>lib/my_gem/version.rb</tt> to make the change - this will automatically be picked up when you rebuild your gem.
27
+
28
+ Your new gem provides some Rake tasks for convenience:
29
+
30
+ * <tt>rake gem</tt> - Build the gem and drop it into the <tt>pkg/</tt> directory for installation.
31
+ * <tt>rake test</tt> - The default test task, it will run the tests in <tt>test</tt>. If this is a newly-created gem, your tests will flunk.
32
+ * <tt>rake github</tt> - Generate <tt>my_gem.gemspec</tt> file to use if you're serving your gem from GitHub (requires flagging your GitHub project as a rubygem).
33
+
34
+ That's it. Enjoy.
35
+
36
+ == License
37
+
38
+ Copyright (c) 2008 Patrick Reagan (mailto:reaganpr@gmail.com)
39
+
40
+ Permission is hereby granted, free of charge, to any person
41
+ obtaining a copy of this software and associated documentation
42
+ files (the "Software"), to deal in the Software without
43
+ restriction, including without limitation the rights to use,
44
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
45
+ copies of the Software, and to permit persons to whom the
46
+ Software is furnished to do so, subject to the following
47
+ conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
54
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
55
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
56
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
57
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
58
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
59
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/simple_gem/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = 'simple-gem'
11
+ s.version = SimpleGem::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.rdoc)
14
+ s.rdoc_options = %w(--main README.rdoc)
15
+ s.summary = "Make gems. Simple."
16
+ s.author = 'Patrick Reagan'
17
+ s.email = 'reaganpr@gmail.com'
18
+ s.homepage = 'http://sneaq.net'
19
+ s.executables = ['simple-gem']
20
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test,templates}/**/*")
21
+ end
22
+
23
+ Rake::GemPackageTask.new(spec) do |pkg|
24
+ pkg.gem_spec = spec
25
+ end
26
+
27
+ Rake::TestTask.new do |t|
28
+ t.libs << 'test'
29
+ t.test_files = FileList["test/**/*_test.rb"]
30
+ t.verbose = true
31
+ end
32
+
33
+ desc 'Generate the gemspec to serve this Gem from Github'
34
+ task :github do
35
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
36
+ File.open(file, 'w') {|f| f << spec.to_ruby }
37
+ puts "Created gemspec: #{file}"
38
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'simple_gem/gem'
4
+
5
+ if ARGV[0]
6
+ gem = SimpleGem::Gem.new(`pwd`.strip, ARGV[0])
7
+ gem.generate
8
+ else
9
+ puts "Please specify a name for your gem"
10
+ end
@@ -0,0 +1,2 @@
1
+ require 'simple_gem/version'
2
+ require 'simple_gem/gem'
@@ -0,0 +1,61 @@
1
+ require 'erb'
2
+
3
+ module SimpleGem
4
+ class Gem
5
+
6
+ attr_reader :root_path, :name
7
+
8
+ def initialize(path, name)
9
+ @root_path = path
10
+ self.name = name
11
+ end
12
+
13
+ def name=(name)
14
+ @name = name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
15
+ end
16
+
17
+ def module_name
18
+ transform_name {|part| part.capitalize }
19
+ end
20
+
21
+ def ruby_name
22
+ transform_name('_') {|part| part.downcase }
23
+ end
24
+
25
+ def generate
26
+ generate_root_directory
27
+ generate_subdirectories
28
+ generate_file('gitignore.erb', '.gitignore')
29
+ generate_file('lib.rb.erb', "lib/#{self.ruby_name}.rb")
30
+ generate_file('lib_version.rb.erb', "lib/#{self.ruby_name}/version.rb")
31
+ generate_file('Rakefile.erb', 'Rakefile')
32
+ generate_file('README.rdoc.erb', 'README.rdoc')
33
+ generate_file('test_helper.rb.erb', 'test/test_helper.rb')
34
+ generate_file('test.rb.erb', "test/unit/#{self.ruby_name}_test.rb")
35
+ end
36
+
37
+ private
38
+ def transform_name(glue = nil, &block)
39
+ self.name.split(/[_-]/).map {|part| block.call(part) }.join(glue)
40
+ end
41
+
42
+ def generate_root_directory
43
+ FileUtils.mkdir("#{self.root_path}/#{self.name}")
44
+ end
45
+
46
+ def generate_subdirectories
47
+ ['lib', 'test', "lib/#{self.ruby_name}", 'test/unit'].each do |dir|
48
+ FileUtils.mkdir("#{self.root_path}/#{self.name}/#{dir}")
49
+ end
50
+ end
51
+
52
+ def generate_file(source, output)
53
+ source_file = File.dirname(__FILE__) + "/../../templates/#{source}"
54
+ output_file = "#{self.root_path}/#{self.name}/#{output}"
55
+
56
+ erb = ERB.new(File.read(source_file))
57
+ File.open(output_file, 'w') {|f| f << erb.result(binding) }
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleGem
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 4
6
+ TINY = 1
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ = <%= self.module_name %>
2
+
3
+ == Description
4
+
5
+ Describe your gem here ...
6
+
7
+ == Installation
8
+
9
+ sudo gem install <%= self.name %>
10
+
11
+ == Usage
12
+
13
+ require '<%= self.ruby_name %>'
14
+
15
+ == License
16
+
17
+ Copyright (c) <year> <copyright holders>
18
+
19
+ Permission is hereby granted, free of charge, to any person
20
+ obtaining a copy of this software and associated documentation
21
+ files (the "Software"), to deal in the Software without
22
+ restriction, including without limitation the rights to use,
23
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the
25
+ Software is furnished to do so, subject to the following
26
+ conditions:
27
+
28
+ The above copyright notice and this permission notice shall be
29
+ included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
33
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
36
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/<%= self.ruby_name %>/version'
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = '<%= self.name %>'
9
+ s.version = <%= self.module_name %>::Version.to_s
10
+ s.has_rdoc = true
11
+ s.extra_rdoc_files = %w(README.rdoc)
12
+ s.rdoc_options = %w(--main README.rdoc)
13
+ s.summary = "This gem does ... "
14
+ s.author = 'First Last'
15
+ s.email = 'user@example.com'
16
+ s.homepage = 'http://my-site.net'
17
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
18
+ # s.executables = ['<%= self.name %>']
19
+
20
+ # s.add_dependency('gem_name', '~> 0.0.1')
21
+ end
22
+
23
+ Rake::GemPackageTask.new(spec) do |pkg|
24
+ pkg.gem_spec = spec
25
+ end
26
+
27
+ Rake::TestTask.new do |t|
28
+ t.libs << 'test'
29
+ t.test_files = FileList["test/**/*_test.rb"]
30
+ t.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+
36
+ Rcov::RcovTask.new(:coverage) do |t|
37
+ t.libs = ['test']
38
+ t.test_files = FileList["test/**/*_test.rb"]
39
+ t.verbose = true
40
+ t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
41
+ end
42
+
43
+ task :default => :coverage
44
+
45
+ rescue LoadError
46
+ warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
47
+ task :default => :test
48
+ end
49
+
50
+
51
+ desc 'Generate the gemspec to serve this Gem from Github'
52
+ task :github do
53
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
54
+ File.open(file, 'w') {|f| f << spec.to_ruby }
55
+ puts "Created gemspec: #{file}"
56
+ end
@@ -0,0 +1,3 @@
1
+ /pkg/
2
+ /doc/
3
+ /coverage/
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ # require '<%= self.ruby_name %>/...'
@@ -0,0 +1,13 @@
1
+ module <%= self.module_name %>
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class <%= self.module_name %>Test < Test::Unit::TestCase
4
+
5
+ describe "An instance of the <%= self.module_name %> class" do
6
+
7
+ it "should flunk" do
8
+ flunk "Please provide some tests"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'throat_punch'
6
+
7
+ require File.dirname(__FILE__) + '/../lib/<%= self.ruby_name %>'
@@ -0,0 +1,113 @@
1
+ require 'rubygems'
2
+ require 'context'
3
+ require 'matchy'
4
+
5
+ require File.dirname(__FILE__) + '/../../lib/simple_gem/gem'
6
+
7
+ module SimpleGem
8
+ class GemTest < Test::Unit::TestCase
9
+
10
+ def self.should_generate(expectations)
11
+ name = expectations[:from].sub(/\W/, '')
12
+ describe "An instance of Gem when given the name: #{name} name" do
13
+ before do
14
+ path = '/this/path'
15
+ @name = expectations[:from]
16
+ @gem = Gem.new(path, @name)
17
+ end
18
+
19
+ expectations.each do |k,v|
20
+ unless k == :from
21
+ it "should know its #{k}" do
22
+ @gem.send(k).should == v
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ should_generate :name => 'simple_gem',
30
+ :module_name => 'SimpleGem',
31
+ :ruby_name => 'simple_gem',
32
+ :from => 'SimpleGem'
33
+
34
+
35
+ should_generate :name => 'simple-gem',
36
+ :module_name => 'SimpleGem',
37
+ :ruby_name => 'simple_gem',
38
+ :from => 'simple-gem'
39
+
40
+ should_generate :name => 'simple_gem',
41
+ :module_name => 'SimpleGem',
42
+ :ruby_name => 'simple_gem',
43
+ :from => 'simple_gem'
44
+
45
+ should_generate :name => 'simple_gem',
46
+ :module_name => 'SimpleGem',
47
+ :ruby_name => 'simple_gem',
48
+ :from => 'simpleGem'
49
+
50
+ describe "An instance of Gem" do
51
+ before { @path = '/this/path' }
52
+
53
+ it "should know its root path" do
54
+ Gem.new(@path, 'name').root_path.should == @path
55
+ end
56
+
57
+ context "when generating the directory structure" do
58
+
59
+ before do
60
+ @tmp_dir = File.dirname(__FILE__) + '/../../tmp'
61
+ FileUtils.mkdir(@tmp_dir) unless File.exist?(@tmp_dir)
62
+
63
+ @name = 'simple-gem'
64
+ Gem.new(@tmp_dir, @name).generate
65
+ end
66
+
67
+ after do
68
+ FileUtils.rm_rf(@tmp_dir)
69
+ end
70
+
71
+ it "should be able to make the root directory" do
72
+ File.exist?("#{@tmp_dir}/#{@name}").should == true
73
+ end
74
+
75
+ %w(lib test lib/simple_gem test/unit).each do |dir|
76
+ it "should create the #{dir} subdirectory" do
77
+ File.exist?("#{@tmp_dir}/#{@name}/#{dir}").should == true
78
+ end
79
+ end
80
+
81
+ it "should create the main library file" do
82
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem.rb").should == true
83
+ end
84
+
85
+ it "should create the version file" do
86
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem/version.rb").should == true
87
+ end
88
+
89
+ it "should create the main Rakefile" do
90
+ File.exist?("#{@tmp_dir}/#{@name}/Rakefile").should == true
91
+ end
92
+
93
+ it "should create the README file" do
94
+ File.exist?("#{@tmp_dir}/#{@name}/README.rdoc").should == true
95
+ end
96
+
97
+ it "should generate the test helper file" do
98
+ File.exist?("#{@tmp_dir}/#{@name}/test/test_helper.rb").should == true
99
+ end
100
+
101
+ it "should generate the test file" do
102
+ File.exist?("#{@tmp_dir}/#{@name}/test/unit/simple_gem_test.rb").should == true
103
+ end
104
+
105
+ it "should generate the .gitignore file" do
106
+ File.exist?("#{@tmp_dir}/#{@name}/.gitignore").should == true
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
113
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Reagan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-20 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: reaganpr@gmail.com
18
+ executables:
19
+ - simple-gem
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - lib/simple_gem/gem.rb
28
+ - lib/simple_gem/version.rb
29
+ - lib/simple_gem.rb
30
+ - test/simple_gem/gem_test.rb
31
+ - templates/gitignore.erb
32
+ - templates/lib.rb.erb
33
+ - templates/lib_version.rb.erb
34
+ - templates/Rakefile.erb
35
+ - templates/README.rdoc.erb
36
+ - templates/test.rb.erb
37
+ - templates/test_helper.rb.erb
38
+ has_rdoc: true
39
+ homepage: http://sneaq.net
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.4
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Make gems. Simple.
67
+ test_files: []
68
+