#11381: Ignore config.eager_load=true for rake #11389

Merged
merged 1 commit into from Jul 10, 2013

Projects

None yet

6 participants

@pftg
Contributor
pftg commented Jul 10, 2013

Closes #11381

@pftg pftg commented on the diff Jul 10, 2013
railties/test/application/rake_test.rb
@@ -9,7 +9,6 @@ class RakeTest < ActiveSupport::TestCase
def setup
build_app
boot_rails
- FileUtils.rm_rf("#{app_path}/config/environments")
pftg
pftg Jul 10, 2013 Contributor

I'm not sure, why this added. But for current version it's useless.

Contributor
pftg commented Jul 10, 2013

@josevalim may your review this PR.

miry commented Jul 10, 2013

👍

Member

👍

Member

Thanks @pftg ! Have you investigated why setting the config option is not enough?

Contributor
pftg commented Jul 10, 2013

@josevalim, default config/environments/production.rb has config.eager_load = true which invoked on loading environment https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L295 and overide https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L294. (Environment loads only on invoking rake task, after we setup config.eager_load = false). After in initializer :eager_load! do https://github.com/rails/rails/blob/master/railties/lib/rails/application/finisher.rb#L53 we have config.eager_load == true, but I think expected value should be false

Member

@pftg Thanks a lot! Couldn't we simply then move the config.eager_load=false to the line after require_environment! and avoid overriding the whole def eager_load method?

Contributor
pftg commented Jul 10, 2013

I'm also looking for more clean solution, maybe adding new initializer with setting eager_load to false.

But for now Finisher.initializers_for(self) runs in require_environment!, and config.eager_load=false after require_environment will be usable only for next rake tasks only.

Member

@pftg there is a before_initialize callback that we could use. Try this:

ActiveSupport.on_load(:before_initialize) { config.eager_load = false }

Or:

ActiveSupport.on_load(:before_initialize) { |app| app.config.eager_load = false }

Could you please give it a try?

Contributor
pftg commented Jul 10, 2013

Cool, thanks. I'm on my way to try it!

Member

@pftg Nice, let me know so we can merge this, thanks! :)

Contributor
pftg commented Jul 10, 2013

@josevalim, sorry for delay. I updated PR. before_initialize works like a charm. Thanks!

@josevalim josevalim merged commit e7e81b4 into rails:master Jul 10, 2013
Member

❤️ 💚 💙 💛 💜

Contributor
pftg commented Jul 10, 2013

Thanks! 🆒

@roman-zaharenkov

I have only one question, why should we ignore eager load for rake?

Owner

See the linked issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment