gemsmith 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ = v0.2.0
2
+
3
+ * Fixed typo in upgrade generator doc.
4
+ * Fixed README typo with command line options.
5
+ * Added Ruby on Rails skeleton generation support.
6
+ * Added RSpec skeleton generation support.
7
+ * Added a cli.rb template with basic Thor setup for binary skeletons.
8
+ * Added binary executable name to gemspec template for binary skeletons.
9
+ * Added gem dependencies to gemspec template for binary and RSpec skeletons.
10
+ * Added proper support for underscoring/camelcasing gem names and classes during skeleton generation.
11
+ * Added common setup options to the README template.
12
+ * Added Ruby on Rails requirements to the README template (only if the Rails options is used).
13
+ * Added Ruby on Rails generator templates for installs and upgrades.
14
+ * Added Git initialization, addition, and first commit message of all skeleton files during gem creation.
15
+ * Updated the gem description.
16
+ * Updated the documentation to include Bundler rake tasks.
17
+
1
18
  = v0.1.0
2
19
 
3
20
  * Initial version.
@@ -6,12 +6,17 @@ command then you'll enjoy this gem since it is essentially an enhanced version o
6
6
 
7
7
  = Features
8
8
 
9
- * Common custom settings that you can configure once and use for every new gem that you build.
10
- * Additional skeleton files such as a README, CHANGELOG, and LICENCE (which you pretty much always need).
9
+ * Builds a gem skeleton with Bundler functionality in mind.
10
+ * Allows for common settings that you can configure once and use for every new gem that you build.
11
+ * Supports binary skeletons with Thor[https://github.com/wycats/thor] command line functionality.
12
+ * Supports {Ruby on Rails}[http://rubyonrails.org] skeletons.
13
+ * Supports RSpec[http://rspec.info] test skeletons.
14
+ * Adds commonly needed README, CHANGELOG, LICENSE, etc. template files.
11
15
 
12
16
  = Requirements
13
17
 
14
- * A desire to develop professional gems.
18
+ * Bundler[https://github.com/carlhuda/bundler]
19
+ * Basic familiarity with gem building.
15
20
 
16
21
  = Setup
17
22
 
@@ -34,8 +39,8 @@ simply create the following file:
34
39
  :company_name: Red Alchmist
35
40
  :company_url: http://www.redalchemist.com
36
41
 
37
- NOTE: All of the options above are optional. You don't have to create the setting.yml at all or you can pick and
38
- choose what you want to define. Up to you. If you don't specify any settings then everything defaults as follows:
42
+ NOTE: All options above are optional. You don't have to create the setting.yml at all or you can pick and
43
+ choose what options to define. Up to you. If no options are configured, then the default options are as follows:
39
44
 
40
45
  gem_platform: Gem::Platform::RUBY
41
46
  author_name: <git user name>
@@ -46,15 +51,25 @@ choose what you want to define. Up to you. If you don't specify any settings the
46
51
 
47
52
  = Usage
48
53
 
49
- From the command line, type: tweeter help
54
+ From the command line, type: gemsmith help
50
55
 
51
56
  gemsmith -c, [create=GEM_NAME] # Create new gem.
52
57
  gemsmith -h, [help] # Show this message.
53
58
  gemsmith -v, [version] # Show version.
54
59
 
55
- For more gem creation options, type: tweeter help create
60
+ For more gem creation options, type: gemsmith help create
56
61
 
57
- -b, [--bin] # Add binary to gem build.
62
+ -r, [--rspec] # Add RSpec support.
63
+ # Default: true
64
+ -b, [--bin] # Adds binary support.
65
+ -R, [--rails] # Adds Rails support.
66
+
67
+ Also, don't forget that once you have created your gem skeleton, the following rake tasks are also
68
+ available to you via Bundler (i.e. rake -T):
69
+
70
+ rake build # Build <gem>-<version>.gem into the pkg directory
71
+ rake install # Build and install <gem>-<version>.gem into system gems
72
+ rake release # Create tag v0.1.1 and build and push <gem>-<version>.gem to Rubygems
58
73
 
59
74
  = Author
60
75
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Brooke Kuhlmann"]
10
10
  s.email = ["brooke@redalchemist.com"]
11
11
  s.homepage = "http://www.redalchemist.com"
12
- s.summary = "Craft new gems with custom settings."
13
- s.description = "Craft new gems with custom settings and reduce setup redundancy."
12
+ s.summary = "Ruby gem skeleton generation for the professional gemsmith."
13
+ s.description = "Ruby gem skeleton generation for the professional gemsmith. Includes custom settings, binary, Ruby on Rails, and RSpec support. "
14
14
 
15
15
  s.rdoc_options << "CHANGELOG.rdoc"
16
16
  s.add_dependency "thor", "~> 0.14.0"
@@ -25,13 +25,15 @@ module Gemsmith
25
25
 
26
26
  desc "-c, [create=GEM_NAME]", "Create new gem."
27
27
  map "-c" => :create
28
- method_option :bin, :aliases => "-b", :desc => "Add binary to gem build.", :type => :boolean, :default => false
28
+ method_option :bin, :aliases => "-b", :desc => "Adds binary support.", :type => :boolean, :default => false
29
+ method_option :rails, :aliases => "-R", :desc => "Adds Rails support.", :type => :boolean, :default => false
30
+ method_option :rspec, :aliases => "-r", :desc => "Add RSpec support.", :type => :boolean, :default => true
29
31
  def create name
30
32
  shell.say "\nCreating gem..."
31
33
 
32
34
  # Initialize options.
33
- gem_name = name.downcase
34
- gem_class = gem_name.capitalize
35
+ gem_name = underscore name
36
+ gem_class = classify gem_name
35
37
  author_name = @settings[:author_name] || `git config user.name`.chomp || "TODO: Write full name here."
36
38
  author_url = @settings[:author_url] || "TODO: Write home page URL here."
37
39
  template_options = {
@@ -43,12 +45,16 @@ module Gemsmith
43
45
  :author_url => author_url,
44
46
  :company_name => (@settings[:company_name] || author_name),
45
47
  :company_url => (@settings[:company_url] || author_url),
46
- :year => Time.now.year
48
+ :year => Time.now.year,
49
+ :bin => options[:bin],
50
+ :rails => options[:rails],
51
+ :rspec => options[:rspec]
47
52
  }
48
53
 
49
- # Apply templates.
54
+ # Configure templates.
50
55
  target_path = File.join Dir.pwd, gem_name
51
- empty_directory File.join(target_path, "lib", gem_name)
56
+
57
+ # Default templates.
52
58
  template "README.rdoc.tmp", File.join(target_path, "README.rdoc"), template_options
53
59
  template "CHANGELOG.rdoc.tmp", File.join(target_path, "CHANGELOG.rdoc"), template_options
54
60
  template "LICENSE.rdoc.tmp", File.join(target_path, "LICENSE.rdoc"), template_options
@@ -58,8 +64,41 @@ module Gemsmith
58
64
  template "gem.gemspec.tmp", File.join(target_path, "#{gem_name}.gemspec"), template_options
59
65
  template File.join("lib", "gem.rb.tmp"), File.join(target_path, "lib", "#{gem_name}.rb"), template_options
60
66
  template File.join("lib", "gem", "version.rb.tmp"), File.join(target_path, "lib", gem_name, "version.rb"), template_options
67
+
68
+ # Binary (optional).
61
69
  if options[:bin]
62
70
  template File.join("bin", "gem.tmp"), File.join(target_path, "bin", gem_name), template_options
71
+ template File.join("lib", "gem", "cli.rb.tmp"), File.join(target_path, "lib", gem_name, "cli.rb"), template_options
72
+ end
73
+
74
+ # Ruby on Rails (optional).
75
+ if options[:rails]
76
+ # ActionController
77
+ template File.join("lib", "gem", "action_controller", "class_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_controller", "class_methods.rb"), template_options
78
+ template File.join("lib", "gem", "action_controller", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_controller", "instance_methods.rb"), template_options
79
+ # ActionView
80
+ template File.join("lib", "gem", "action_view", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_view", "instance_methods.rb"), template_options
81
+ # ActiveRecord
82
+ template File.join("lib", "gem", "active_record", "class_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "active_record", "class_methods.rb"), template_options
83
+ template File.join("lib", "gem", "active_record", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "active_record", "instance_methods.rb"), template_options
84
+ # Generators
85
+ empty_directory File.join(target_path, "lib", "generators", gem_name, "templates")
86
+ template File.join("lib", "generators", "gem", "install", "install_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "install", "install_generator.rb"), template_options
87
+ template File.join("lib", "generators", "gem", "upgrade", "upgrade_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "upgrade", "upgrade_generator.rb"), template_options
88
+ end
89
+
90
+ # RSpec (optional).
91
+ if options[:rspec]
92
+ template "rspec.tmp", File.join(target_path, ".rspec"), template_options
93
+ template File.join("spec", "spec_helper.rb.tmp"), File.join(target_path, "spec", "spec_helper.rb"), template_options
94
+ template File.join("spec", "gem_spec.rb.tmp"), File.join(target_path, "spec", "#{gem_name}_spec.rb"), template_options
95
+ end
96
+
97
+ # Git
98
+ Dir.chdir(target_path) do
99
+ `git init`
100
+ `git add .`
101
+ `git commit -a -n -m "Gemsmith skeleton created."`
63
102
  end
64
103
 
65
104
  shell.say "Gem created: #{gem_name}\n\n"
@@ -77,6 +116,32 @@ module Gemsmith
77
116
  end
78
117
 
79
118
  private
119
+
120
+ # Transforms a camelcased string to an underscored equivalent (code stolen from the Ruby on Rails ActiveSupport underscore method).
121
+ # ==== Examples
122
+ # * "ExampleGem" -> "example_gem"
123
+ # * "SSLGem" -> "ssl_gem"
124
+ # ==== Parameters
125
+ # * +string+ - The string to underscore.
126
+ def underscore string
127
+ string = string.to_s.dup
128
+ string.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2'
129
+ string.gsub! /([a-z\d])([A-Z])/, '\1_\2'
130
+ string.tr! "-", "_"
131
+ string.downcase
132
+ end
133
+
134
+ # Transforms a lowercased/camelcased to a proper class name (code inspired by the Ruby on Rails ActiveSupport classify method).
135
+ # ==== Examples
136
+ # * "example" -> "example"
137
+ # * "my_cool_gem" -> "MyCoolGem"
138
+ # ==== Parameters
139
+ # * +string+ - The string to classify.
140
+ def classify string
141
+ string = string.to_s.dup
142
+ string.gsub!(/(^.{1}|_.)/) {$1.upcase}
143
+ string.tr '_', ''
144
+ end
80
145
 
81
146
  # Load settings.
82
147
  def load_settings
@@ -3,9 +3,19 @@
3
3
  = Features
4
4
 
5
5
  = Requirements
6
-
6
+ <% if config[:rails] %>
7
+ 1. {Ruby on Rails}[http://rubyonrails.org].
8
+ <% end %>
7
9
  = Setup
8
10
 
11
+ Type the following from the command line to install:
12
+
13
+ gem install <%= config[:gem_name] %>
14
+
15
+ Add the following to your Gemfile:
16
+
17
+ gem "<%= config[:gem_name] %>"
18
+
9
19
  = Usage
10
20
 
11
21
  = Author
@@ -13,9 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.description = "TODO: Write gem description."
14
14
 
15
15
  s.rdoc_options << "CHANGELOG.rdoc"
16
- # s.add_dependency "thor", "~> 1.0.0"
17
- # s.add_development_dependency "some_gem"
18
- # s.executables << "gemsmith"
16
+ <% if config[:bin] %>s.add_dependency "thor"<% end %>
17
+ <% if config[:rspec] %>s.add_development_dependency "rspec"<% end %>
18
+ <% if config[:bin] %>s.add_development_dependency "aruba"<% end %>
19
+ <% if config[:bin] %>s.executables << "<%= config[:gem_name] %>"<% end %>
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
@@ -1,5 +1,33 @@
1
+ # Dependencies
1
2
  require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "version.rb"
3
+ <% if config[:rails] %>
4
+ require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "active_record", "class_methods.rb"
5
+ require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "active_record", "instance_methods.rb"
6
+ require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "action_view", "instance_methods.rb"
7
+ require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "action_controller", "class_methods.rb"
8
+ require File.join File.dirname(__FILE__), "<%= config[:gem_name] %>", "action_controller", "instance_methods.rb"
9
+ <% end %>
2
10
 
11
+ # Namespace
3
12
  module <%= config[:gem_class] %>
4
13
  # Placeholder.
5
14
  end
15
+ <% if config[:rails] %>
16
+ # Rails Enhancements
17
+ if defined? Rails
18
+ # Model
19
+ if defined? ActiveRecord
20
+ ActiveRecord::Base.send :include, <%= config[:gem_class] %>::ActiveRecord
21
+ end
22
+
23
+ # View
24
+ if defined? ActionView
25
+ ActionView::Base.send :include, <%= config[:gem_class] %>::InstanceMethods
26
+ end
27
+
28
+ # Controller
29
+ if defined? ActionController
30
+ ActionController::Base.send :include, <%= config[:gem_class] %>::ActionController
31
+ end
32
+ end
33
+ <% end %>
@@ -0,0 +1,18 @@
1
+ module <%= config[:gem_class] %>
2
+ module ActionController
3
+ def self.included base
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ # TODO - Rename the method name to your liking.
9
+ def is_<%= config[:gem_name] %>_enhanced options = {}
10
+ self.send :include, InstanceMethods
11
+
12
+ # Default Options
13
+ class_inheritable_reader :<%= config[:gem_name] %>_options
14
+ write_inheritable_attribute :<%= config[:gem_name] %>_options
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module <%= config[:gem_class] %>
2
+ module ActionController
3
+ module InstanceMethods
4
+ # TODO - Write some code.
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module <%= config[:gem_class] %>
2
+ module ActionView
3
+ module InstanceMethods
4
+ # TODO - Write some code.
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module <%= config[:gem_class] %>
2
+ module ActiveRecord
3
+ def self.included base
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ # TODO - Rename the method name to your liking.
9
+ def is_<%= config[:gem_name] %>_enhanced options = {}
10
+ self.send :include, InstanceMethods
11
+
12
+ # Default Options
13
+ class_inheritable_reader :<%= config[:gem_name] %>_options
14
+ write_inheritable_attribute :<%= config[:gem_name] %>_options
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module <%= config[:gem_class] %>
2
+ module ActiveRecord
3
+ module InstanceMethods
4
+ # TODO - Write some code.
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require "yaml"
2
+ require "thor"
3
+
4
+ module <%= config[:gem_class] %>
5
+ class CLI < Thor
6
+
7
+ # Initialize.
8
+ def initialize args = [], options = {}, config = {}
9
+ super
10
+ end
11
+
12
+ desc "-v, [version]", "Show version."
13
+ map "-v" => :version
14
+ def version
15
+ print_version
16
+ end
17
+
18
+ desc "-h, [help]", "Show this message."
19
+ def help task = nil
20
+ shell.say and super
21
+ end
22
+
23
+ private
24
+
25
+ # Print version information.
26
+ def print_version
27
+ shell.say "<%= config[:gem_class] %> " + VERSION
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module <%= config[:gem_class] %>
2
+ class InstallGenerator < Rails::Generators::Base
3
+ desc "Installs additional <%= config[:gem_class] %> resources."
4
+
5
+ # Override the default source path by pulling from a shared templates directory for all generators.
6
+ def self.source_root
7
+ @source_root ||= File.join(File.dirname(__FILE__), "..", "templates")
8
+ end
9
+
10
+ # Let others know about you.
11
+ def self.banner
12
+ "rails generate <%= config[:gem_name] %>:install"
13
+ end
14
+
15
+ # TODO - Explain yourself.
16
+ def copy_files
17
+ # TODO - Add your fancy/schmancy install code here.
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module <%= config[:gem_class] %>
2
+ class UpgradeGenerator < Rails::Generators::Base
3
+ desc "Upgrades previously installed <%= config[:gem_class] %> resources."
4
+
5
+ # Override the default source path by pulling from a shared templates directory for all generators.
6
+ def self.source_root
7
+ @source_root ||= File.join(File.dirname(__FILE__), "..", "templates")
8
+ end
9
+
10
+ # Let others know about you.
11
+ def self.banner
12
+ "rails generate <%= config[:gem_name] %>:upgrade"
13
+ end
14
+
15
+ # TODO - Explain yourself.
16
+ def copy_files
17
+ # TODO - Add your fancy/schmancy upgrade code here.
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe "<%= config[:gem_class] %>" do
4
+ it "should be tested" do
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "<%= config[:gem_name] %>"
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Gemsmith
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemsmith
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brooke Kuhlmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-05 00:00:00 Z
18
+ date: 2011-06-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thor
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: "0"
62
62
  type: :development
63
63
  version_requirements: *id003
64
- description: Craft new gems with custom settings and reduce setup redundancy.
64
+ description: "Ruby gem skeleton generation for the professional gemsmith. Includes custom settings, binary, Ruby on Rails, and RSpec support. "
65
65
  email:
66
66
  - brooke@redalchemist.com
67
67
  executables:
@@ -90,7 +90,18 @@ files:
90
90
  - lib/gemsmith/templates/gem.gemspec.tmp
91
91
  - lib/gemsmith/templates/gitignore.tmp
92
92
  - lib/gemsmith/templates/lib/gem.rb.tmp
93
+ - lib/gemsmith/templates/lib/gem/action_controller/class_methods.rb.tmp
94
+ - lib/gemsmith/templates/lib/gem/action_controller/instance_methods.rb.tmp
95
+ - lib/gemsmith/templates/lib/gem/action_view/instance_methods.rb.tmp
96
+ - lib/gemsmith/templates/lib/gem/active_record/class_methods.rb.tmp
97
+ - lib/gemsmith/templates/lib/gem/active_record/instance_methods.rb.tmp
98
+ - lib/gemsmith/templates/lib/gem/cli.rb.tmp
93
99
  - lib/gemsmith/templates/lib/gem/version.rb.tmp
100
+ - lib/gemsmith/templates/lib/generators/gem/install/install_generator.rb.tmp
101
+ - lib/gemsmith/templates/lib/generators/gem/upgrade/upgrade_generator.rb.tmp
102
+ - lib/gemsmith/templates/rspec.tmp
103
+ - lib/gemsmith/templates/spec/gem_spec.rb.tmp
104
+ - lib/gemsmith/templates/spec/spec_helper.rb.tmp
94
105
  - lib/gemsmith/version.rb
95
106
  homepage: http://www.redalchemist.com
96
107
  licenses: []
@@ -121,9 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
132
  requirements: []
122
133
 
123
134
  rubyforge_project:
124
- rubygems_version: 1.8.4
135
+ rubygems_version: 1.8.5
125
136
  signing_key:
126
137
  specification_version: 3
127
- summary: Craft new gems with custom settings.
138
+ summary: Ruby gem skeleton generation for the professional gemsmith.
128
139
  test_files: []
129
140