1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

This commit is contained in:
José Valim 2009-12-29 11:52:06 +01:00
parent 66604b2e0e
commit 1a4d909c68
3 changed files with 38 additions and 8 deletions

View file

@ -3,6 +3,10 @@ require 'active_support/secure_random'
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 @@ module Rails::Generators
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 @@ module Rails::Generators
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 @@ module Rails::Generators
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

View file

@ -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"

View file

@ -149,6 +149,19 @@ class AppGeneratorTest < GeneratorsTestCase
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=[])