lib/rails/generators/actions.rb in railties-3.1.12 vs lib/rails/generators/actions.rb in railties-3.2.0.rc1
- old
+ new
@@ -66,14 +66,40 @@
options.each do |option, value|
parts << ":#{option} => #{value.inspect}"
end
in_root do
- append_file "Gemfile", "gem #{parts.join(", ")}\n", :verbose => false
+ str = "gem #{parts.join(", ")}"
+ str = " " + str if @in_group
+ str = "\n" + str
+ append_file "Gemfile", str, :verbose => false
end
end
+ # Wraps gem entries inside a group.
+ #
+ # ==== Example
+ #
+ # gem_group :development, :test do
+ # gem "rspec-rails"
+ # end
+ #
+ def gem_group(*names, &block)
+ name = names.map(&:inspect).join(", ")
+ log :gemfile, "group #{name}"
+
+ in_root do
+ append_file "Gemfile", "\ngroup #{name} do", :force => true
+
+ @in_group = true
+ instance_eval(&block)
+ @in_group = false
+
+ append_file "Gemfile", "\nend\n", :force => true
+ end
+ end
+
# Add the given source to Gemfile
#
# ==== Example
#
# add_source "http://gems.github.com/"
@@ -90,18 +116,19 @@
# If options :env is specified, the line is appended to the corresponding
# file in config/environments.
#
def environment(data=nil, options={}, &block)
sentinel = /class [a-z_:]+ < Rails::Application/i
+ env_file_sentinel = /::Application\.configure do/
data = block.call if !data && block_given?
in_root do
if options[:env].nil?
- inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
+ inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
else
- Array.wrap(options[:env]).each do|env|
- append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
+ Array.wrap(options[:env]).each do |env|
+ inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false
end
end
end
end
alias :application :environment
@@ -112,15 +139,15 @@
#
# git :init
# git :add => "this.file that.rb"
# git :add => "onefile.rb", :rm => "badfile.cxx"
#
- def git(command={})
- if command.is_a?(Symbol)
- run "git #{command}"
+ def git(commands={})
+ if commands.is_a?(Symbol)
+ run "git #{commands}"
else
- command.each do |cmd, options|
+ commands.each do |cmd, options|
run "git #{cmd} #{options}"
end
end
end
@@ -224,10 +251,10 @@
# rake("db:migrate", :env => "production")
# rake("gems:install", :sudo => true)
#
def rake(command, options={})
log :rake, command
- env = options[:env] || 'development'
+ env = options[:env] || ENV["RAILS_ENV"] || 'development'
sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
end
# Just run the capify command in root