Permalink
Browse files

Add rails app --edge and rails app --dev

  • Loading branch information...
1 parent 66604b2 commit 1a4d909c6845c091a04e2533ab89502de4130c1b @josevalim josevalim committed Dec 29, 2009
@@ -3,6 +3,10 @@
require 'rails/version' unless defined?(Rails::VERSION)
module Rails::Generators
+ # We need to store the RAILS_DEV_PATH in a constant, otherwise the path
+ # can change in Ruby 1.8.7 when we FileUtils.cd.
+ RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
+
class AppGenerator < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
add_shebang_option!
@@ -15,17 +19,22 @@ class AppGenerator < Base
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an application template (can be a filesystem path or URL)."
+ class_option :dev, :type => :boolean, :default => false,
+ :desc => "Setup the application with Gemfile pointing to your Rails checkout"
+
+ class_option :edge, :type => :boolean, :default => false,
+ :desc => "Setup the application with Gemfile pointing to Rails repository"
+
class_option :skip_activerecord, :type => :boolean, :aliases => "-O", :default => false,
- :desc => "Skip ActiveRecord files"
+ :desc => "Skip ActiveRecord files"
class_option :skip_testunit, :type => :boolean, :aliases => "-T", :default => false,
- :desc => "Skip TestUnit files"
+ :desc => "Skip TestUnit files"
class_option :skip_prototype, :type => :boolean, :aliases => "-J", :default => false,
- :desc => "Skip Prototype files"
+ :desc => "Skip Prototype files"
- # Add Rails options
- #
+ # Add bin/rails options
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
:desc => "Show Rails version number and quit"
@@ -173,7 +182,6 @@ def set_default_accessors!
end
# Define file as an alias to create_file for backwards compatibility.
- #
def file(*args, &block)
create_file(*args, &block)
end
@@ -190,6 +198,10 @@ def app_secret
ActiveSupport::SecureRandom.hex(64)
end
+ def dev_or_edge?
+ options.dev? || options.edge?
+ end
+
def self.banner
"#{$0} #{self.arguments.map(&:usage).join(' ')} [options]"
end
@@ -1,9 +1,14 @@
# Edit this Gemfile to bundle your application's dependencies.
-
+<% if !dev_or_edge? %>
gem "rails", "<%= Rails::VERSION::STRING %>"
+<% end -%>
## Bundle edge rails:
-# gem "rails", :git => "git://github.com/rails/rails.git"
+<%- if options.dev? -%>
+gem "rails", :path => "<%= Rails::Generators::RAILS_DEV_PATH %>"
+<%- else -%>
+<%= "# " unless options.edge? %>gem "rails", :git => "git://github.com/rails/rails.git"
+<%- end -%>
## Bundle the gems you use:
# gem "bj"
@@ -149,6 +149,19 @@ def test_file_is_added_for_backwards_compatibility
assert_file 'lib/test_file.rb', 'heres test data'
end
+ def test_dev_option
+ run_generator ["--dev"]
+ rails_path = File.expand_path('../../..', Rails.root)
+ dev_gem = %(gem "rails", :path => #{rails_path.inspect})
+ assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/
+ end
+
+ def test_edge_option
+ run_generator ["--edge"]
+ edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git")
+ assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/
+ end
+
protected
def run_generator(args=[])

2 comments on commit 1a4d909

KieranP commented on 1a4d909 Jan 1, 2010

It seems that

gem "rails", :path => "/path/to/rails"

won't correctly bundle the parts of Rails needed to run, so --dev is effectively broken. I'm not sure if this is an issue with the latest bundler.

For now, you can get around it by using :git instead of :path, like so:

gem "rails", :git => "/path/to/rails"
Member

Thanks KieranP. Carl and Yehuda are fixing bundler :path, so --dev will be working properly soon!

Please sign in to comment.