I am curious if anyone would know how to reload a meta-model into what seems to be the global constants in Rails. Basically, this is a factory that creates models on the fly that contain AASM workflows, validations and other goodies. I can get this to work correctly if I restart the server but I want to be able ‘reset’ the constant that references the meta model if the code needs a refresh. Does anyone know a way to do this? This code below works for the current process but I need this to refresh much like what happens when one adds a new file and ActiveSupport::Dependencies pick it up and reloads it.
This departs from a fundamental convention in constant autoloading:
Constant Foo is expected to be autoloaded from a file called foo.rb
that lives somewhere in config.autoload_paths.
In your situation there are no files for these models, so I would like
to understand the details further to see the implications and whether
there is a way to do what you want.
For example, let's suppose there is a metaprogrammed model is called
Foo. What happens if I do
bin/rails runner Foo
Does it work? If it does, how is that definition on-the-fly
implemented in your application?
Right you are about the files and autoloading. All of the files that I was meta~programming were just ActiveRecord models, so what I did was take what was being instance/class_eval’d and dumped it into a model class.
So now when I make a change to the model, say change up a workflow (which is really a gui version of AASM with several modifications) or add a new has_many field and need these changes to take effect they will because the model file will be re-written at the end of that process… Ok, so that is good for right now, but I need to demo this on a production server asap. So really my problem is convincing the production server that it needs to re-compile this model. I am reading up of a good way to do this but unfortunately I haven’t found anything that will help me…yet. Phusion Passenger will allow you to re-start the app but doesn’t have any way to tell it to recompile a file based on the last time it was modified.
I have my ear to the ground if anyone has any ideas. As of right now, I am not sure this is possible but…there is always a way