Add --dev and --edge options to rails plugin new
This commit is contained in:
parent
5c8b48ab4b
commit
e51e9e2db0
|
@ -74,6 +74,40 @@ module Rails
|
|||
options[:template]
|
||||
end
|
||||
end
|
||||
|
||||
def rails_gemfile_entry
|
||||
if options.dev?
|
||||
<<-GEMFILE
|
||||
gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
|
||||
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
GEMFILE
|
||||
elsif options.edge?
|
||||
<<-GEMFILE
|
||||
gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
GEMFILE
|
||||
else
|
||||
<<-GEMFILE
|
||||
gem 'rails', '#{Rails::VERSION::STRING}'
|
||||
|
||||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
# gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
# gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
GEMFILE
|
||||
end
|
||||
end
|
||||
|
||||
def bundle_if_dev_or_edge
|
||||
bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
|
||||
run "#{bundle_command} install" if dev_or_edge?
|
||||
end
|
||||
|
||||
def dev_or_edge?
|
||||
options.dev? || options.edge?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -302,8 +302,7 @@ module Rails
|
|||
end
|
||||
|
||||
def bundle_if_dev_or_edge
|
||||
bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
|
||||
run "#{bundle_command} install" if dev_or_edge?
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -354,10 +353,6 @@ module Rails
|
|||
ActiveSupport::SecureRandom.hex(64)
|
||||
end
|
||||
|
||||
def dev_or_edge?
|
||||
options.dev? || options.edge?
|
||||
end
|
||||
|
||||
def gem_for_database
|
||||
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
|
||||
case options[:database]
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
source 'http://rubygems.org'
|
||||
|
||||
<%- if options.dev? -%>
|
||||
gem 'rails', :path => '<%= Rails::Generators::RAILS_DEV_PATH %>'
|
||||
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
<%- elsif options.edge? -%>
|
||||
gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
<%- else -%>
|
||||
gem 'rails', '<%= Rails::VERSION::STRING %>'
|
||||
|
||||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
# gem 'arel', :git => 'git://github.com/rails/arel.git'
|
||||
# gem "rack", :git => "git://github.com/rack/rack.git"
|
||||
<%- end -%>
|
||||
<%= rails_gemfile_entry -%>
|
||||
|
||||
<% unless options[:skip_active_record] -%>
|
||||
gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %>
|
||||
|
|
|
@ -91,6 +91,12 @@ module Rails
|
|||
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
||||
:desc => "Skip Git ignores and keeps"
|
||||
|
||||
class_option :dev, :type => :boolean, :default => false,
|
||||
:desc => "Setup the plugin with Gemfile pointing to your Rails checkout"
|
||||
|
||||
class_option :edge, :type => :boolean, :default => false,
|
||||
:desc => "Setup the plugin with Gemfile pointing to Rails repository"
|
||||
|
||||
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
|
||||
:desc => "Show this help message and quit"
|
||||
|
||||
|
@ -158,6 +164,10 @@ module Rails
|
|||
super
|
||||
end
|
||||
|
||||
def bundle_if_dev_or_edge
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.banner
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", :git => "http://github.com/rails/rails.git"
|
||||
gem "arel" , :git => "http://github.com/rails/arel.git"
|
||||
gem "rack" , :git => "http://github.com/rack/rack.git"
|
||||
<%= rails_gemfile_entry -%>
|
||||
|
||||
gem "capybara", ">= 0.3.9"
|
||||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
|
||||
|
|
|
@ -130,6 +130,19 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
|||
assert_match /It works!/, silence(:stdout){ generator.invoke_all }
|
||||
end
|
||||
|
||||
def test_dev_option
|
||||
generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
|
||||
silence(:stdout){ generator.invoke_all }
|
||||
rails_path = File.expand_path('../../..', Rails.root)
|
||||
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
|
||||
end
|
||||
|
||||
def test_edge_option
|
||||
generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
|
||||
silence(:stdout){ generator.invoke_all }
|
||||
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def action(*args, &block)
|
||||
|
|
Loading…
Reference in New Issue