Skip to content
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

Use load when loading static service models #536

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def self.create_service_model_from_name(name)
def self.create_service_model(ar_model)
file_path = model_to_file_path(ar_model)
if File.exist?(file_path)
require file_path
# class reloading in development causes require to no-op when it should load
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this always been true or is this new as of zeitwerk? I thought the whole point of class reloading is that it would internally re-load the file.

Copy link
Member Author

@kbrock kbrock Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not in a path that reflect the package. This must be confusing the loader.

Do you want me to experiment with moving the files into a path that reflectst he package?

This method would change to:

def self.create_service_model(ar_model)
  unless File.exist?(model_to_file_path(ar_model))
    dynamic_service_model_creation(ar_model, service_model_superclass(ar_model))
  end
end

# since we will never require this file, using load is not a big loss
load file_path
model_name_from_active_record_model(ar_model).safe_constantize
else
dynamic_service_model_creation(ar_model, service_model_superclass(ar_model))
Expand Down