-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails: Support reloading of classes in development #122
Comments
Hey @pfeiffer, I'n not entirely sure on what I could do to support this. Would you mind helping with the implementation? Cheers |
The problem that is breaking reloading is that mappings are not readded if the class is redefined: contentful_model/lib/contentful_model/base.rb Line 123 in b286afd
If I override this method to return false, the class gets reloaded fine in development. class TestModel < ContentfulModel::Base
# ....
def self.mapping?
false
end
end This happens because the rails environment persists class variables like I don't know if that helps. |
Here is how this problem can be fixed module MyApp
class Application < Rails::Application
config.to_prepare do
ContentfulModel.configuration.entry_mapping.each do |content_type_id, model|
ContentfulModel.configuration.entry_mapping[content_type_id] = Object.const_get(model.to_s)
end
end
end
end It is still an expiemintal solution I am keeping an eye on it in my current project. |
@dlitvakb Do you still need more information in order to understand how to improve this? This has been one of the most frustrating parts of using this library :( |
At the moment changing a method in a class descending from ContentfulModel::Base requires full reload of Rails environment.
Example:
Changing the
#title
method:And then reloading:
The text was updated successfully, but these errors were encountered: