ggem 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kelredd-simple-gem.gemspec
4
+ gemspec
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ggem (1.0.0)
5
+ bundler (~> 1.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ leftright (0.9.1)
11
+ test-belt (1.0.1)
12
+ leftright (~> 0.9.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ ggem!
19
+ test-belt (= 1.0.1)
@@ -0,0 +1,60 @@
1
+ = ggem
2
+
3
+ == Description
4
+
5
+ Quickly, easily, consistantly generate a ruby gem project ready to build, test, and deploy. Uses Bundler's gem building features.
6
+
7
+ == Installation
8
+
9
+ gem install ggem
10
+
11
+ == Usage
12
+
13
+ $ ggem my-gem
14
+
15
+ This creates a folder and some files for developing, testing, and building a gem. The command is pretty forgiving with the name you supply, it will automatically transform anything that is CamelCased into something more ruby-like. If you have existing folders/files it will just add/overwrite where necessary and not remove anything.
16
+
17
+ The gem will generate with bundler (http://github.com/carlhuda/bundler/) and test-belt (http://github.com/kelredd/test-belt) gems as development dependencies. They are brought in automatically to make unit testing and releasing your new gem easy. Remove their calls from the generated Rakefile and test helper if you don't want to use them.
18
+
19
+ After generating your gem, add information about your gem to both the gemspec and README files. The default version number is "0.0.1", 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.
20
+
21
+ Your new gem provides some Rake tasks for convenience:
22
+
23
+ * all the bundler gem rake tasks (http://github.com/carlhuda/bundler/)
24
+ * all the testing rake task stuff from test-belt (http://github.com/kelredd/test-belt)
25
+
26
+ That's it. Enjoy.
27
+
28
+ == Acceptance Testing
29
+
30
+ # clone this repo
31
+ $ bundle install
32
+ $ rake test
33
+
34
+ == Credit
35
+ This gem came about from work I did on a fork of Patrick Reagan's (https://github.com/reagent) simple-gem. The original source can be found here: https://github.com/kelredd/simple-gem.
36
+
37
+ == License
38
+
39
+ Copyright (c) 2008-2011 Kelly Redding (mailto:kelly@kelredd.com)
40
+
41
+ Permission is hereby granted, free of charge, to any person
42
+ obtaining a copy of this software and associated documentation
43
+ files (the "Software"), to deal in the Software without
44
+ restriction, including without limitation the rights to use,
45
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ copies of the Software, and to permit persons to whom the
47
+ Software is furnished to do so, subject to the following
48
+ conditions:
49
+
50
+ The above copyright notice and this permission notice shall be
51
+ included in all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
54
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
55
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
57
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
58
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
59
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
60
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'test_belt/rake_tasks'
5
+ TestBelt::RakeTasks.for :test
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ggem/gem'
4
+
5
+ if ARGV[0]
6
+ the_gem = GGem::Gem.new(`pwd`.strip, ARGV[0])
7
+ the_gem.save
8
+ else
9
+ puts "Please specify a name for your gem"
10
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ggem/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ggem"
7
+ s.version = SimpleGem::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kelly Redding"]
10
+ s.email = ["kelly@kelredd.com"]
11
+ s.homepage = "http://github.com/kelredd/ggem"
12
+ s.summary = %q{"Juh Gem", baby! (this makes gems)}
13
+ s.description = %q{Quickly, easily, consistantly generate a ruby gem project ready to build, test, and deploy. Uses Bundler's gem building features.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency("bundler", ["~> 1.0"])
21
+ s.add_development_dependency("test-belt", ["= 1.0.1"])
22
+ end
@@ -0,0 +1 @@
1
+ require 'ggem/gem'
@@ -0,0 +1,38 @@
1
+ require 'fileutils'
2
+ require 'ggem/template'
3
+
4
+ module GGem
5
+ class Gem
6
+
7
+ attr_reader :root_path, :name
8
+
9
+ def initialize(path, name)
10
+ @root_path = path
11
+ self.name = name
12
+ end
13
+
14
+ def name=(name)
15
+ @name = name.gsub(/([A-Z])([a-z])/, '-\1\2').sub(/^-/, '').downcase
16
+ end
17
+
18
+ def module_name
19
+ @module_name ||= transform_name {|part| part.capitalize }
20
+ end
21
+ def ruby_name
22
+ @ruby_name ||= transform_name('_') {|part| part.downcase }
23
+ end
24
+
25
+ def save
26
+ Template.new(self).save
27
+ end
28
+
29
+ private
30
+
31
+ def transform_name(glue = nil, &block)
32
+ self.name.split(/[_-]/).collect do |part|
33
+ yield part if block_given?
34
+ end.join(glue)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,53 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+
4
+ module GGem
5
+ class Template
6
+ SOURCE_PATH =
7
+ def initialize(ggem)
8
+ @gem = ggem
9
+ end
10
+
11
+ def save
12
+ save_folder # (gems root path)
13
+ save_folder "lib/#{@gem.ruby_name}"
14
+ save_folder "test"
15
+
16
+ save_file('gitignore.erb', '.gitignore')
17
+ save_file('Gemfile.erb', 'Gemfile')
18
+ save_file('gemspec.erb', "#{@gem.name}.gemspec")
19
+ save_file('Rakefile.erb', 'Rakefile')
20
+ save_file('README.rdoc.erb', 'README.rdoc')
21
+
22
+ save_file('lib.rb.erb', "lib/#{@gem.ruby_name}.rb")
23
+ save_file('lib_version.rb.erb', "lib/#{@gem.ruby_name}/version.rb")
24
+
25
+ save_file('test_env.rb.erb', 'test/env.rb')
26
+ save_file('test_helper.rb.erb', 'test/helper.rb')
27
+ save_file('test.rb.erb', "test/#{@gem.ruby_name}_test.rb")
28
+ end
29
+
30
+ private
31
+
32
+ def save_folder(relative_path=nil)
33
+ FileUtils.mkdir_p(File.join([
34
+ @gem.root_path, @gem.name, relative_path
35
+ ].compact))
36
+ ["lib/#{@gem.ruby_name}", 'test'].each do |dir|
37
+ end
38
+ end
39
+
40
+ def save_file(source, output)
41
+ source_file = File.join(File.dirname(__FILE__), 'template_file', source)
42
+ output_file = File.join(@gem.root_path, @gem.name, output)
43
+
44
+ if File.exists?(source_file)
45
+ erb = ERB.new(File.read(source_file))
46
+ File.open(output_file, 'w') {|f| f << erb.result(binding) }
47
+ else
48
+ raise ArgumentError, "the source file '#{source_file}' does not exist"
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify dependencies in <%= @gem.name %>.gemspec
4
+ gemspec
@@ -0,0 +1,38 @@
1
+ = <%= @gem.module_name %>
2
+
3
+ == Description
4
+
5
+ TODO: Write a description
6
+
7
+ == Installation
8
+
9
+ gem install <%= @gem.name %>
10
+
11
+ == Usage
12
+
13
+ require '<%= @gem.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,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'test_belt/rake_tasks'
5
+ TestBelt::RakeTasks.for :test
6
+
7
+ task :default => :build
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "<%= @gem.ruby_name %>/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "<%= @gem.name %>"
7
+ s.version = <%= @gem.module_name %>::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["TODO: Write your name"]
10
+ s.email = ["TODO: Write your email address"]
11
+ s.homepage = "http://github.com/__/<%= @gem.name %>"
12
+ s.summary = %q{TODO: Write a gem summary}
13
+ s.description = %q{TODO: Write a gem description}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency("bundler", ["~> 1.0"])
21
+ s.add_development_dependency("test-belt", ["= 1.0.1"]) # TODO: lock to a specific version for test stability
22
+ # s.add_dependency("gem-name", ["~> 0.0"])
23
+ end
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ .bundle
3
+ *.gem
4
+ *.log
@@ -0,0 +1,3 @@
1
+ module <%= @gem.module_name %>
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ module <%= @gem.module_name %>
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "test/helper"
2
+
3
+ class <%= @gem.module_name %>Test < Test::Unit::TestCase
4
+ include TestBelt
5
+
6
+ context "<%= @gem.module_name %>"
7
+
8
+ should "flunk" do
9
+ flunk "Please provide some tests"
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # Add test and lib paths to the $LOAD_PATH
2
+ [ File.dirname(__FILE__),
3
+ File.join(File.dirname(__FILE__), '..', 'lib')
4
+ ].each do |path|
5
+ full_path = File.expand_path(path)
6
+ $LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
7
+ end
8
+
9
+ require '<%= @gem.ruby_name %>'
10
+
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'test_belt'
3
+ require 'test/env'
4
+
5
+ # TODO: setup test environment here
@@ -0,0 +1,3 @@
1
+ module SimpleGem
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ # Add test and lib paths to the $LOAD_PATH
2
+ [ File.dirname(__FILE__),
3
+ File.join(File.dirname(__FILE__), '..', 'lib')
4
+ ].each do |path|
5
+ full_path = File.expand_path(path)
6
+ $LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
7
+ end
8
+
9
+ require 'ggem'
@@ -0,0 +1,43 @@
1
+ require "test/helper"
2
+ require "test/name_set"
3
+
4
+ module GGem
5
+ class GGemTest < Test::Unit::TestCase
6
+ include TestBelt
7
+
8
+ context "GGem::Gem"
9
+ end
10
+
11
+ class RootPathTest < GGemTest
12
+ should "know its root path" do
13
+ assert_equal TMP_PATH, Gem.new(TMP_PATH, 'a-gem').root_path
14
+ end
15
+ end
16
+
17
+ class NameTest < GGemTest
18
+ [ GGem::NameSet::Simple,
19
+ GGem::NameSet::Underscored,
20
+ GGem::NameSet::HyphenatedOther
21
+ ].each do |ns|
22
+ should_generate_name_set(ns.new)
23
+ end
24
+ end
25
+
26
+ class SaveTest < GGemTest
27
+ NS = GGem::NameSet::Simple.new
28
+
29
+ context "after it's been saved"
30
+ setup_once do
31
+ FileUtils.mkdir_p(TMP_PATH)
32
+ Gem.new(TMP_PATH, NS.variations.first).save
33
+ end
34
+ teardown_once do
35
+ FileUtils.rm_rf(TMP_PATH)
36
+ end
37
+
38
+ should_create_paths((NS.expected_folders + NS.expected_files).collect do |p|
39
+ File.join(TMP_PATH, NS.name, p)
40
+ end)
41
+ end
42
+
43
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'test_belt'
3
+ require 'test/env'
4
+
5
+ class Test::Unit::TestCase
6
+ TMP_PATH = File.expand_path("#{File.dirname(__FILE__)}/../tmp")
7
+
8
+ class << self
9
+
10
+ def should_generate_name_set(name_set)
11
+ name_set.variations.each do |variation|
12
+ [:name, :module_name, :ruby_name].each do |name_type|
13
+ should "know its :#{name_type} given '#{variation}'" do
14
+ the_gem = GGem::Gem.new(TMP_PATH, variation)
15
+ assert_equal name_set.send(name_type), the_gem.send(name_type)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def should_create_paths(*paths)
22
+ paths.flatten.each do |path|
23
+ should "create the path '#{path}'" do
24
+ assert File.exists?(path), "'#{path}' does not exist"
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,65 @@
1
+ module GGem
2
+ module NameSet
3
+
4
+
5
+ class Base
6
+ attr_reader :variations, :name, :module_name, :ruby_name
7
+
8
+ def expected_folders
9
+ [ '',
10
+ 'lib',
11
+ "lib/#{@ruby_name}",
12
+ 'test'
13
+ ]
14
+ end
15
+
16
+ def expected_files
17
+ [ ".gitignore",
18
+ "Gemfile",
19
+ "#{@name}.gemspec",
20
+ "Rakefile",
21
+ "README.rdoc",
22
+
23
+ "lib/#{@ruby_name}.rb",
24
+ "lib/#{@ruby_name}/version.rb",
25
+
26
+ "test/helper.rb",
27
+ "test/env.rb",
28
+ "test/#{@ruby_name}_test.rb"
29
+ ]
30
+ end
31
+ end
32
+
33
+
34
+ class Simple < Base
35
+ def initialize
36
+ @variations = ['simple']
37
+ @name = 'simple'
38
+ @module_name = 'Simple'
39
+ @ruby_name = 'simple'
40
+ end
41
+ end
42
+
43
+
44
+ class Underscored < Base
45
+ def initialize
46
+ @variations = ['my_gem']
47
+ @name = 'my_gem'
48
+ @module_name = 'MyGem'
49
+ @ruby_name = 'my_gem'
50
+ end
51
+ end
52
+
53
+
54
+ class HyphenatedOther < Base
55
+ def initialize
56
+ @variations = ['my-gem', 'MyGem', 'myGem']
57
+ @name = 'my-gem'
58
+ @module_name = 'MyGem'
59
+ @ruby_name = 'my_gem'
60
+ end
61
+ end
62
+
63
+
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ggem
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Kelly Redding
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: test-belt
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ hash: 21
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 1
48
+ version: 1.0.1
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Quickly, easily, consistantly generate a ruby gem project ready to build, test, and deploy. Uses Bundler's gem building features.
52
+ email:
53
+ - kelly@kelredd.com
54
+ executables:
55
+ - ggem
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .bundle/config
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.rdoc
65
+ - Rakefile
66
+ - bin/ggem
67
+ - ggem.gemspec
68
+ - lib/ggem.rb
69
+ - lib/ggem/gem.rb
70
+ - lib/ggem/template.rb
71
+ - lib/ggem/template_file/Gemfile.erb
72
+ - lib/ggem/template_file/README.rdoc.erb
73
+ - lib/ggem/template_file/Rakefile.erb
74
+ - lib/ggem/template_file/gemspec.erb
75
+ - lib/ggem/template_file/gitignore.erb
76
+ - lib/ggem/template_file/lib.rb.erb
77
+ - lib/ggem/template_file/lib_version.rb.erb
78
+ - lib/ggem/template_file/test.rb.erb
79
+ - lib/ggem/template_file/test_env.rb.erb
80
+ - lib/ggem/template_file/test_helper.rb.erb
81
+ - lib/ggem/version.rb
82
+ - pkg/kelredd-simple-gem-1.0.0.gem
83
+ - test/env.rb
84
+ - test/gem_test.rb
85
+ - test/helper.rb
86
+ - test/name_set.rb
87
+ homepage: http://github.com/kelredd/ggem
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.7.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: "\"Juh Gem\", baby! (this makes gems)"
120
+ test_files:
121
+ - test/env.rb
122
+ - test/gem_test.rb
123
+ - test/helper.rb
124
+ - test/name_set.rb