diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-08-06 08:49:00 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-08-06 08:49:00 +0200 |
commit | a8192119840c62bf2a0e564817c172191711b4b2 (patch) | |
tree | 432ae673ce2a219796a634f5769b151f1c0a3af4 /guides | |
parent | ec54acd1e01374f0b5b495d7659181d7382e119e (diff) | |
parent | c294e91d00696e910e05ad1428ba3ce4884bc6a3 (diff) | |
download | rails-a8192119840c62bf2a0e564817c172191711b4b2.tar.gz rails-a8192119840c62bf2a0e564817c172191711b4b2.tar.bz2 rails-a8192119840c62bf2a0e564817c172191711b4b2.zip |
Merge pull request #16359 from skanev/after-bundle-in-rails-templates
Add an after_bundle callback in Rails templates
Conflicts:
railties/CHANGELOG.md
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/4_2_release_notes.md | 3 | ||||
-rw-r--r-- | guides/source/rails_application_templates.md | 24 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 32 |
3 files changed, 56 insertions, 3 deletions
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index 12db528b91..a39dd9ace0 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -85,6 +85,9 @@ Please refer to the [Changelog][railties] for detailed changes. * Introduced `Rails.gem_version` as a convenience method to return `Gem::Version.new(Rails.version)`. ([Pull Request](https://github.com/rails/rails/pull/14101)) +* Introduced an `after_bundle` callback in the Rails templates. + ([Pull Request](https://github.com/rails/rails/pull/16359)) + Action Pack ----------- diff --git a/guides/source/rails_application_templates.md b/guides/source/rails_application_templates.md index 0bd608c007..6512b14e60 100644 --- a/guides/source/rails_application_templates.md +++ b/guides/source/rails_application_templates.md @@ -38,9 +38,11 @@ generate(:scaffold, "person name:string") route "root to: 'people#index'" rake("db:migrate") -git :init -git add: "." -git commit: %Q{ -m 'Initial commit' } +after_bundle do + git :init + git add: "." + git commit: %Q{ -m 'Initial commit' } +end ``` The following sections outline the primary methods provided by the API: @@ -228,6 +230,22 @@ git add: "." git commit: "-a -m 'Initial commit'" ``` +### after_bundle(&block) + +Registers a callback to be executed after the gems are bundled and binstubs +are generated. Useful for all generated files to version control: + +```ruby +after_bundle do + git :init + git add: '.' + git commit: "-a -m 'Initial commit'" +end +``` + +The callbacks gets executed even if `--skip-bundle` and/or `--skip-spring` has +been passed. + Advanced Usage -------------- diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index b3e4505fc0..62e4071935 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -58,6 +58,38 @@ When assigning `nil` to a serialized attribute, it will be saved to the database as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"` when using the `JSON` coder). +### `after_bundle` in Rails templates + +If you have a Rails template that adds all the files in version control, it +fails to add the generated binstubs because it gets executed before Bundler: + +```ruby +# template.rb +generate(:scaffold, "person name:string") +route "root to: 'people#index'" +rake("db:migrate") + +git :init +git add: "." +git commit: %Q{ -m 'Initial commit' } +``` + +You can now wrap the `git` calls in an `after_bundle` block. It will be run +after the binstubs have been generated. + +```ruby +# template.rb +generate(:scaffold, "person name:string") +route "root to: 'people#index'" +rake("db:migrate") + +after_bundle do + git :init + git add: "." + git commit: %Q{ -m 'Initial commit' } +end +``` + Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- |