activegraph
activegraph copied to clipboard
Update Reloading to Support Zeitwerk in Rails Development Environment
ActiveGraph relies on a Rails 3.x method for cache clearing: before_remove_const
.
We are running with the gem in a Rails 7 app. So the method is never called, and as such, we must restart our development server anytime we make a change to a node instance method.
FWIW: There is a Rails guide for upgrading it to Zeitwerk (the latest reloading library).
In our application, we monkey patch this in the initializer. It's one-to-one re-write of the current before_remove_const
method. It's not perfect: we must add each ActiveGraph node (relationships are OK as-is), but it works:
Code example (initializers/neo4j.rb)
unless Rails.application.config.cache_classes
node_classes = [
"StateSecret",
"LaunchCode",
"Bribe",
"User"
]
node_classes.each do |node_class|
Rails.autoloaders.main.on_unload(node_class) do |klass, _abspath|
klass.associations.each_value(&:queue_model_refresh!)
klass::MODELS_FOR_LABELS_CACHE.clear
klass::WRAPPED_CLASSES.each { |c| klass::MODELS_TO_RELOAD << c.name }
klass::WRAPPED_CLASSES.clear
end
end
end
Runtime information:
Neo4j database version: neo4j:4.0.9-community
activegraph
gem version: 10.2.0.beta.1
rails
gem version: 7.0.3
Thank you for the report. We converted all our gems to zeitwerk except this one. I would love to get it done. Will conversion to zeitwerk alone fix your problems? We will probably do it on version 11.1.0 only. Will that work for you?
@klobuczek I'm not sure.
We are running Rails 7 which requires Ruby 2.7.0 or newer in ruby:3.1.2-slim-bulleye
. The latest version of JRuby is 9.3.8.0, which is only compatible with Ruby 2.6.x. So that seems to point to "no".
But this issue has a checklist of issues to fix to get Rails 7 working on JRuby... and they're all checked off. So that seems to point to "yes".
We're not too worried about it at this point. Most of my motivation in opening this issue was to help anyone else that might be trying to accomplish the same thing we are.
@nathancolgate I'm talking about activegraph 11.1.0.alpha.4 with neo4j-ruby-driver 4.4.0.beta.1 which requires ruby 3.1.2 if on MRI
@klobuczek oh! I'm not sure. The README mentions v11 only being available on jRuby.
we have not updated that as we have not released the MRI driver officially yet.
@klobuczek Then that should work for us! Great!