ruby on rails - Run initializer only for Rake tasks -


i'd initializer run when executing rake task, not when running rails server.

what best way differentiate rake invocation , server invocation?

rake allows specify dependencies tasks. best recommended action put rake-specific initialization in own task in turn depends on "environment" task. example:

namespace :myapp     task :custom_environment => :environment         # special initialization stuff here         # or call initializer script     end      task :my_task => :custom_environment         # perform actions need custom setup     end end 

if want make rake-specific directory of initializer scripts have rails proper, implement in our :custom_environment task.

task :custom_environment => :environment     dir.glob("config/rake-initializers/*.rb").each |initializer|         require initializer     end end 

this allows keep rake-specific intializers separate regular initializers. have remember depend on :custom_environment set up.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -