Permalink
Browse files

Merge pull request #20697 from 5t111111/add-block-to-add_source

add_source in Application Template should take a block for gem entries
  • Loading branch information...
guilleiguaran committed Jun 25, 2015
2 parents 5f5e6d9 + e6be33f commit 8cc01e0b2bfa75a613720c535d34e451f5de769c
@@ -503,6 +503,14 @@ Adds a specified source to `Gemfile`:
add_source "http://gems.github.com"
```
This method also takes a block:
```ruby
add_source "http://gems.github.com" do
gem "rspec-rails"
end
```
### `inject_into_file`
Injects a block of code into a defined position in your file.
View
@@ -1,3 +1,7 @@
* Adding support for passing a block to the `add_source` action of a custom generator
*Mike Dalton*, *Hirofumi Wakasugi*
* `assert_file` understands paths with special characters
(eg. `v0.1.4~alpha+nightly`).
@@ -63,12 +63,26 @@ def gem_group(*names, &block)
# Add the given source to +Gemfile+
#
# If block is given, gem entries in block are wrapped into the source group.
#
# add_source "http://gems.github.com/"
def add_source(source, options={})
#
# add_source "http://gems.github.com/" do
# gem "rspec-rails"
# end
def add_source(source, options={}, &block)
log :source, source
in_root do
prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
if block
append_file "Gemfile", "source #{quote(source)} do", force: true
@in_group = true
instance_eval(&block)
@in_group = false
append_file "Gemfile", "\nend\n", force: true
else
prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
end
end
end
@@ -47,6 +47,14 @@ def test_add_source_adds_source_to_gemfile
assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com'/
end
def test_add_source_with_block_adds_source_to_gemfile_with_gem
run_generator
action :add_source, 'http://gems.github.com' do
gem 'rspec-rails'
end
assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/
end
def test_gem_should_put_gem_dependency_in_gemfile
run_generator
action :gem, 'will-paginate'

0 comments on commit 8cc01e0

Please sign in to comment.