ruby on rails - Wipe per request prevents reloading of certain classes -


rails wipes classes , reloads them if detects file change while server running in development mode. have following structure:

app/models/algorithms/algorithms.rb (module algorithms)  app/models/algorithms/algorithm.rb (base class algorithms::algorithm)  app/models/algorithms/algorithm_a.rb (extended classes algorithms::algorithma) app/models/algorithms/algorithm_b.rb (extended classes algorithms::algorithmb) app/models/algorithms/algorithm_c.rb (extended classes algorithms::algorithmc) 

these concrete algorithm classes not instantiated controller, in sidekiq worker classes app/workers, means not inside rails process, inside sidekiq process.

now, if make change file, instance controller, rails wipes classes, , reloads them. great, not reload whole app/models/algorithms directory.

why so? how can configure eagerly load every time? have set config.eager_load true. problem not solved until reference each class 1 after other inside pry session, there loaded again, 1 one.

looking @ documentation on @ http://edgeguides.rubyonrails.org/configuring.html seems can add custom paths eager load.

i quote:

  • config.eager_load when true, eager loads registered config.eager_load_namespaces. includes application, engines, rails frameworks , other registered namespace.

  • config.eager_load_namespaces registers namespaces eager loaded when config.eager_load true. namespaces in list must respond eager_load! method.

what find interesting though, following.

  • config.eager_load_paths accepts array of paths rails eager load on boot if cache classes enabled. defaults every folder in app directory of application.

to me, eager load files well.

i'd try adding following config/application.rb:

config.eager_load_paths += rails.root.join('app/models/algorithms') 

note: works if cache_classes set true.

you can eager load namespace, done doing:

config.config.eager_load_namespaces += algorithms 

and implement method eager_load! handles setup properly.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -