Callbacks are cleared if cache_classes if disabled in development
Zank94 opened this issue · 2 comments
Hello everyone,
I've just ran into the same problems as the ones mentioned in #155, even after updating to 1.8.1
to fix the eager_load
related issue.
To prevent callbacks clearing in development, I have to set config.cache_classes
value to true
, which isn't very convenient since it involves restarting the server for changes to take effect.
Any help would be much appreciated :)
Thanks
Hi @Zank94 I'm sorry to hear that you're having trouble with this. Would you mind sharing more details about this? These caching issues are really tough to debug and it'll make it a load easier to figure out with an example app.
I was also having trouble keeping the event callbacks from being reset. require
is not causing the file to actually be loaded (not sure why... didn't dig in, might be something obvious that I'm missing.)
lib/stripe/engine.rb
eager_load_classes = -> class_names {
class_names.each do |constant|
begin
constant.to_s.camelize.constantize
rescue NameError
require constant
end
end
}
Given this block, I attempted to run both the full paths and the class names.
# Ruby 2.6.3
rails (5.2.4.4)
stripe (5.28.0)
stripe-rails (2.2.1)
rails (>= 5.1)
responders
stripe (>= 3.15.0)
Works once, after initial requests no callbacks executed
config.stripe.eager_load = Dir[Rails.root.join('app/services/stripe_events/*.rb').to_s]
Works, and reloads as files are changed
config.stripe.eager_load = Dir[Rails.root.join('app/services/stripe_events/*.rb').to_s].map do |file|
'::StripeEvents::' + File.basename(file.chomp(File.extname(file))).classify
end
note: eager loading in rspec tests work in both formats.