mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add gem_group support to generators
This commit is contained in:
parent
9da07d1b01
commit
47bc5d0cc8
4 changed files with 61 additions and 1 deletions
|
@ -449,6 +449,15 @@ The above code will put the following line into +Gemfile+:
|
|||
gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master"
|
||||
</ruby>
|
||||
|
||||
h4. +gem_group+
|
||||
|
||||
Wraps gem entries inside a group:
|
||||
|
||||
<ruby>
|
||||
gem_group :development, :test do
|
||||
gem "rspec-rails"
|
||||
end
|
||||
</ruby>
|
||||
|
||||
h4. +add_source+
|
||||
|
||||
|
|
|
@ -60,6 +60,18 @@ Please note that this will NOT install the gems for you and you will have to run
|
|||
bundle install
|
||||
</ruby>
|
||||
|
||||
h4. gem_group(*names, &block)
|
||||
|
||||
Wraps gem entries inside a group.
|
||||
|
||||
For example, if you want to load +rspec-rails+ only in +development+ and +test+ group:
|
||||
|
||||
<ruby>
|
||||
gem_group :development, :test do
|
||||
gem "rspec-rails"
|
||||
end
|
||||
</ruby>
|
||||
|
||||
h4. add_source(source, options = {})
|
||||
|
||||
Adds the given source to the generated application's +Gemfile+.
|
||||
|
|
|
@ -68,7 +68,32 @@ module Rails
|
|||
end
|
||||
|
||||
in_root do
|
||||
append_file "Gemfile", "gem #{parts.join(", ")}\n", :verbose => false
|
||||
str = "gem #{parts.join(", ")}\n"
|
||||
str = " " + str if @in_group
|
||||
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\n", :force => true
|
||||
|
||||
@in_group = true
|
||||
instance_eval &block
|
||||
@in_group = false
|
||||
|
||||
append_file "Gemfile", "end\n", :force => true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -102,6 +102,20 @@ class ActionsTest < Rails::Generators::TestCase
|
|||
assert_file 'Gemfile', /gem "rspec-rails"$/
|
||||
end
|
||||
|
||||
def test_gem_group_should_wrap_gems_in_a_group
|
||||
run_generator
|
||||
|
||||
action :gem_group, :development, :test do
|
||||
gem 'rspec-rails'
|
||||
end
|
||||
|
||||
action :gem_group, :test do
|
||||
gem 'fakeweb'
|
||||
end
|
||||
|
||||
assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/
|
||||
end
|
||||
|
||||
def test_environment_should_include_data_in_environment_initializer_block
|
||||
run_generator
|
||||
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
|
||||
|
|
Loading…
Reference in a new issue