diff options
author | Arthur Neves <arthurnn@gmail.com> | 2016-11-01 12:36:00 -0400 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2016-11-01 12:37:23 -0400 |
commit | 4a8edc0d822c852a1944d822bc798e0ddb8a7cee (patch) | |
tree | 73dc3721d787be1a6c75cedf036afb9672f1837c /railties/lib | |
parent | 6b5ad4979ed2ba268755c74c804a2e22eee1d5b8 (diff) | |
parent | 8360d9944be602ea97aa309ad89753219e50b093 (diff) | |
download | rails-4a8edc0d822c852a1944d822bc798e0ddb8a7cee.tar.gz rails-4a8edc0d822c852a1944d822bc798e0ddb8a7cee.tar.bz2 rails-4a8edc0d822c852a1944d822bc798e0ddb8a7cee.zip |
Merge PR #26052
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/railtie.rb | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index eb3f5d4ee9..f890b1f13a 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -132,27 +132,19 @@ module Rails end def rake_tasks(&blk) - @rake_tasks ||= [] - @rake_tasks << blk if blk - @rake_tasks + register_block_for(:rake_tasks, &blk) end def console(&blk) - @load_console ||= [] - @load_console << blk if blk - @load_console + register_block_for(:load_console, &blk) end def runner(&blk) - @load_runner ||= [] - @load_runner << blk if blk - @load_runner + register_block_for(:runner, &blk) end def generators(&blk) - @generators ||= [] - @generators << blk if blk - @generators + register_block_for(:generators, &blk) end def abstract_railtie? @@ -186,6 +178,17 @@ module Rails ActiveSupport::Inflector.underscore(string).tr("/", "_") end + # receives an instance variable identifier, set the variable value if is + # blank and append given block to value, which will be used later in + # `#each_registered_block(type, &block)` + def register_block_for(type, &blk) + var_name = "@#{type}" + blocks = instance_variable_get(var_name) || instance_variable_set(var_name, []) + blocks << blk if blk + blocks + end + + # If the class method does not have a method, then send the method call # to the Railtie instance. def method_missing(name, *args, &block) @@ -241,6 +244,7 @@ module Rails private + # run `&block` in every registered block in `#register_block_for` def each_registered_block(type, &block) klass = self.class while klass.respond_to?(type) |