Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Improve dependency management and gemspec file for plugins #2282

wants to merge 1 commit into from

4 participants


The current gemspec files generated by "rails plugin new" are not optimal for creating gems. They do not include full meta-information, nor do they include dependencies.

Bundler can now manage dependencies declared in the .gemspec file through the addition of a simple "gemspec" directive in your Gemfile. This allows dependencies to be declared once, and applies to both base and development dependencies. For more information, check out:

This pull request includes a refactoring of the Gemfile and .gemspec files generated by "rails plugin new". Dependencies are now managed in the .gemspec file where possible. Comments have been added to both files explaining dependency management choices.

In addition, the .gemspec file has been updated to include more meta-information, such as author and email. Defaults have been added that include "TODO", which prevents gems from being built without review. The version has been extracted into a separate file, to be consistent with bundler and svenfuchs/gem-release. Also, an app/mailers directory has been included (I'm not sure why this was omitted?).

Hopefully, all of these changes will eliminate the need to run a separate tool such as Bundler or Jeweler to create a gem template which then needs to be merged with the output of "rails plugin new". Merging is a messy, error-prone process that leaves you wishing for a cleaner alternative.

I know this is rather late in the RC cycle, but please consider these changes for 3.1. Thanks!

@dgeb dgeb Moved dependencies from Gemfile to gemspec to eliminate redundant dec…
…larations. Also filled out the gemspec file with instructions, added an external version file, and templated a mailers directory.

Please send this pull request for master. It's not fixing any bugs, so I won't merge to 3-1-stable. We can consider backporting after 3.1.0 is released.

@tenderlove tenderlove closed this

I will send this to master. However, there is one small bug that this addresses: the app/mailers directory isn't included in "rails plugin new --full". Let me know if you want me to submit a separate issue and pull request for that fix in 3-1-stable.


Please provide a pull request adding app/mailers to 3-1-stable.


Please see #2287 for the app/mailers fix.


@dgeb also I'd like to see this for master but in atomic and more meaningful commits. You're doing lot of things in just one commit. Please split them, each of one should have one purpose. Thanks!


Fair enough @spastorino - that's actually my normal process, but I lumped these changes together because I've seen requests on other pull requests to squash commits. Live and learn - I'm pretty new around here :)

Anyway, I'll restructure this pull request for master, albeit without the app/mailers fix already in 2287. Thanks for everyone's input.


@dgeb We use to ask for squashes when people is committing atomic stuff in different commits.
I've seen pull requests with one commit, one which revert the original commit, another one to add a test, another adding more tests and another with the patch for this new test, true story :P.


@spastorino - Crazy! No doubt squash can be both over AND under applied :)


I've resubmitted this for master in several atomic commits: #2295

In testing, I determined that there actually is a bug that this addresses for 3-1-stable: "rake test" doesn't pass for generated plugins by default without specifying the "--full" or "--mountable" options. This is due to a missing dependency issue: the database database_gemfile_entry is only included for full or mountable plugins, and yet it's required to run tests regardless. On a related note, the database gem should probably be a development, not a base, dependency by default.

I'm not sure if these minor issues make my pull request worthwhile for 3-1-stable. However, I've had a lot of trouble determining best practices for using "rails plugin new", and I think these changes would help get developers off to a good start with this new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2011
  1. @dgeb

    Moved dependencies from Gemfile to gemspec to eliminate redundant dec…

    dgeb authored
    …larations. Also filled out the gemspec file with instructions, added an external version file, and templated a mailers directory.
This page is out of date. Refresh to see the latest.
2  railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -19,6 +19,7 @@ def app
empty_directory_with_gitkeep "app/controllers"
empty_directory_with_gitkeep "app/views"
empty_directory_with_gitkeep "app/helpers"
+ empty_directory_with_gitkeep "app/mailers"
empty_directory_with_gitkeep "app/assets/images/#{name}"
@@ -46,6 +47,7 @@ def gitignore
def lib
template "lib/%name%.rb"
template "lib/tasks/%name%_tasks.rake"
+ template "lib/%name%/version.rb"
if full?
template "lib/%name%/engine.rb"
38 railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
@@ -1,12 +1,36 @@
-# Provide a simple gemspec so you can easily use your
-# project in your rails apps through git.
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+# Maintain your gem's version:
+require "<%= name %>/version"
+# Describe your gem and declare its dependencies: do |s|
- = "<%= name %>"
- s.summary = "Insert <%= camelized %> summary."
- s.description = "Insert <%= camelized %> description."
+ = "<%= name %>"
+ s.version = <%= camelized %>::VERSION
+ s.authors = ["TODO: Your name"]
+ = ["TODO: Your email"]
+ s.homepage = ""
+ s.summary = "TODO: Summary of <%= camelized %>."
+ s.description = "TODO: Description of <%= camelized %>."
+ s.rubyforge_project = "<%= name %>"
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
<% unless options.skip_test_unit? -%>
s.test_files = Dir["test/**/*"]
<% end -%>
- s.version = "0.0.1"
+ s.require_paths = ["lib"]
+ # If your gem is dependent on a specific version (or higher) of Rails:
+ <%= '# ' if || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>"
+<% unless options[:skip_javascript] -%>
+ # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript:
+ # s.add_dependency "<%= "#{options[:javascript]}-rails" %>"
+<% end -%>
+ # Declare development-specific dependencies:
+ s.add_development_dependency "<%= gem_for_database %>"
+ # s.add_development_dependency "rspec"
16 railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -1,14 +1,16 @@
source ""
-<%= rails_gemfile_entry -%>
+# Specify your gem's dependencies in <%= name %>.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
-<% if full? -%>
-<%= database_gemfile_entry -%>
-<% end -%>
+<% if || options.edge? -%>
+# A dependency on dev or edge Rails needs to be declared here instead of in
+# your gemspec. Once you can lock this dependency down to a specific version,
+# move it to your gemspec.
+<%= rails_gemfile_entry -%>
-<% if mountable? -%>
-<%= javascript_gemfile_entry -%>
<% end -%>
# To use debugger
# <%= ruby_debugger_gemfile_entry %>
0  railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory
No changes.
3  railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb
@@ -0,0 +1,3 @@
+module <%= camelized %>
+ VERSION = "0.0.1"
Something went wrong with that request. Please try again.