reagent-simple-gem 0.1.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.
data/README.markdown ADDED
@@ -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 `Rakefile` and `README.markdown` files. The default version number is "0.1.0", but if you want to change that, take a look at `lib/my_gem/version.rb` 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
+ * `rake gem` - Build the gem and drop it into the `pkg/` directory for installation.
31
+ * `rake test` - The default test task, it will run the tests in `test`. If this is a newly-created gem, your tests will flunk.
32
+ * `rake github` - Generate `my_gem.gemspec` 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 (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.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
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.markdown)
14
+ s.summary = "Make gems. Simple."
15
+ s.author = 'Patrick Reagan'
16
+ s.email = 'reaganpr@gmail.com'
17
+ s.homepage = 'http://sneaq.net'
18
+ s.executables = ['simple-gem']
19
+ s.files = %w(README.markdown Rakefile) + Dir.glob("{lib,test,templates}/**/*")
20
+ end
21
+
22
+ Rake::GemPackageTask.new(spec) do |pkg|
23
+ pkg.gem_spec = spec
24
+ end
25
+
26
+ Rake::TestTask.new do |t|
27
+ t.libs << 'test'
28
+ t.test_files = FileList["test/**/*_test.rb"]
29
+ t.verbose = true
30
+ end
31
+
32
+ desc 'Generate the gemspec to serve this Gem from Github'
33
+ task :github do
34
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
35
+ File.open(file, 'w') {|f| f << spec.to_ruby }
36
+ puts "Created gemspec: #{file}"
37
+ end
data/bin/simple-gem ADDED
@@ -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
data/lib/simple_gem.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'simple_gem/version'
2
+ require 'simple_gem/gem'
@@ -0,0 +1,59 @@
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('lib.rb.erb', "lib/#{self.ruby_name}.rb")
29
+ generate_file('lib_version.rb.erb', "lib/#{self.ruby_name}/version.rb")
30
+ generate_file('Rakefile.erb', 'Rakefile')
31
+ generate_file('README.markdown.erb', 'README.markdown')
32
+ generate_file('test.rb.erb', "test/#{self.ruby_name}_test.rb")
33
+ end
34
+
35
+ private
36
+ def transform_name(glue = nil, &block)
37
+ self.name.split(/[_-]/).map {|part| block.call(part) }.join(glue)
38
+ end
39
+
40
+ def generate_root_directory
41
+ FileUtils.mkdir("#{self.root_path}/#{self.name}")
42
+ end
43
+
44
+ def generate_subdirectories
45
+ ['lib', 'test', "lib/#{self.ruby_name}"].each do |dir|
46
+ FileUtils.mkdir("#{self.root_path}/#{self.name}/#{dir}")
47
+ end
48
+ end
49
+
50
+ def generate_file(source, output)
51
+ source_file = File.dirname(__FILE__) + "/../../templates/#{source}"
52
+ output_file = "#{self.root_path}/#{self.name}/#{output}"
53
+
54
+ erb = ERB.new(File.read(source_file))
55
+ File.open(output_file, 'w') {|f| f << erb.result(binding) }
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleGem
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
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,39 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/<%= self.ruby_name %>/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = '<%= self.name %>'
11
+ s.version = <%= self.module_name %>::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.markdown)
14
+ s.summary = "This gem does ... "
15
+ s.author = 'First Last'
16
+ s.email = 'user@example.com'
17
+ s.homepage = 'http://my-site.net'
18
+ s.files = %w(README.markdown Rakefile) + Dir.glob("{lib,test}/**/*")
19
+ # s.executables = ['<%= self.name %>']
20
+
21
+ # s.add_dependency('gem_name', '>=0.0.1')
22
+ end
23
+
24
+ Rake::GemPackageTask.new(spec) do |pkg|
25
+ pkg.gem_spec = spec
26
+ end
27
+
28
+ Rake::TestTask.new do |t|
29
+ t.libs << 'test'
30
+ t.test_files = FileList["test/**/*_test.rb"]
31
+ t.verbose = true
32
+ end
33
+
34
+ desc 'Generate the gemspec to serve this Gem from Github'
35
+ task :github do
36
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
37
+ File.open(file, 'w') {|f| f << spec.to_ruby }
38
+ puts "Created gemspec: #{file}"
39
+ end
@@ -0,0 +1 @@
1
+ # 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
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ class <%= self.module_name %>Test < Test::Unit::TestCase
4
+
5
+ def test_truth
6
+ flunk "Please provide some tests"
7
+ end
8
+
9
+ end
@@ -0,0 +1,104 @@
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
+ describe "An instance of Gem when given a #{expectations[:from]} name" do
12
+ before do
13
+ path = '/this/path'
14
+ @name = expectations[:from]
15
+ @gem = Gem.new(path, @name)
16
+ end
17
+
18
+ expectations.each do |k,v|
19
+ unless k == :from
20
+ it "should know its #{k}" do
21
+ @gem.send(k).should == v
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ should_generate :name => 'simple_gem',
29
+ :module_name => 'SimpleGem',
30
+ :ruby_name => 'simple_gem',
31
+ :from => 'SimpleGem'
32
+
33
+
34
+ should_generate :name => 'simple-gem',
35
+ :module_name => 'SimpleGem',
36
+ :ruby_name => 'simple_gem',
37
+ :from => 'simple-gem'
38
+
39
+ should_generate :name => 'simple_gem',
40
+ :module_name => 'SimpleGem',
41
+ :ruby_name => 'simple_gem',
42
+ :from => 'simple_gem'
43
+
44
+ should_generate :name => 'simple_gem',
45
+ :module_name => 'SimpleGem',
46
+ :ruby_name => 'simple_gem',
47
+ :from => 'simpleGem'
48
+
49
+ describe "An instance of Gem" do
50
+ before { @path = '/this/path' }
51
+
52
+ it "should know its root path" do
53
+ Gem.new(@path, 'name').root_path.should == @path
54
+ end
55
+
56
+ context "when generating the directory structure" do
57
+
58
+ before do
59
+ @tmp_dir = File.dirname(__FILE__) + '/../../tmp'
60
+ FileUtils.mkdir(@tmp_dir) unless File.exist?(@tmp_dir)
61
+
62
+ @name = 'simple-gem'
63
+ Gem.new(@tmp_dir, @name).generate
64
+ end
65
+
66
+ after do
67
+ FileUtils.rm_rf(@tmp_dir)
68
+ end
69
+
70
+ it "should be able to make the root directory" do
71
+ File.exist?("#{@tmp_dir}/#{@name}").should == true
72
+ end
73
+
74
+ %w(lib test lib/simple_gem).each do |dir|
75
+ it "should create the #{dir} subdirectory" do
76
+ File.exist?("#{@tmp_dir}/#{@name}/#{dir}").should == true
77
+ end
78
+ end
79
+
80
+ it "should create the main library file" do
81
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem.rb").should == true
82
+ end
83
+
84
+ it "should create the version file" do
85
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem/version.rb").should == true
86
+ end
87
+
88
+ it "should create the main Rakefile" do
89
+ File.exist?("#{@tmp_dir}/#{@name}/Rakefile").should == true
90
+ end
91
+
92
+ it "should create the README file" do
93
+ File.exist?("#{@tmp_dir}/#{@name}/README.markdown").should == true
94
+ end
95
+
96
+ it "should generate the test file" do
97
+ File.exist?("#{@tmp_dir}/#{@name}/test/simple_gem_test.rb").should == true
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reagent-simple-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Reagan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-30 00:00:00 -07:00
13
+ default_executable: simple-gem
14
+ dependencies: []
15
+
16
+ description:
17
+ email: reaganpr@gmail.com
18
+ executables:
19
+ - simple-gem
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - README.markdown
26
+ - Rakefile
27
+ - lib/simple_gem
28
+ - lib/simple_gem/gem.rb
29
+ - lib/simple_gem/version.rb
30
+ - lib/simple_gem.rb
31
+ - test/simple_gem
32
+ - test/simple_gem/gem_test.rb
33
+ - templates/lib.rb.erb
34
+ - templates/lib_version.rb.erb
35
+ - templates/Rakefile.erb
36
+ - templates/README.markdown.erb
37
+ - templates/test.rb.erb
38
+ - bin/simple-gem
39
+ has_rdoc: true
40
+ homepage: http://sneaq.net
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Make gems. Simple.
65
+ test_files: []
66
+