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

Fix dependency on the engines load order when adding paths #65

Merged
merged 1 commit into from
Jan 5, 2022
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
28 changes: 17 additions & 11 deletions lib/solidus_support/engine_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def self.included(engine)

config.to_prepare(&method(:activate))

enable_solidus_engine_support('backend') if SolidusSupport.backend_available?
enable_solidus_engine_support('frontend') if SolidusSupport.frontend_available?
enable_solidus_engine_support('api') if SolidusSupport.api_available?
enable_solidus_engine_support('backend')
enable_solidus_engine_support('frontend')
enable_solidus_engine_support('api')
end
end

Expand Down Expand Up @@ -82,17 +82,23 @@ def solidus_subscribers_root
#
# @see #load_solidus_decorators_from
def enable_solidus_engine_support(engine)
paths['app/controllers'] << "lib/controllers/#{engine}"
paths['app/views'] << "lib/views/#{engine}"
initializer "#{name}_#{engine}_paths", before: :initialize_dependency_mechanism do
if SolidusSupport.send(:"#{engine}_available?")
Copy link
Member

Choose a reason for hiding this comment

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

Does this if need to be here (as opposed to wrapping the whole method) because SolidusSupport.send(:"#{engine}_available?") needs to be evaluated when the initializer block is executed? If yes, maybe it's worth documenting it, at least in the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's it. Outside the initializer block, we're still at load time execution time, so the frontend might not be available yet. I updated the commit message to make it clearer.

paths['app/controllers'] << "lib/controllers/#{engine}"
paths['app/views'] << "lib/views/#{engine}"
end
end

path = root.join("lib/decorators/#{engine}")
if SolidusSupport.send(:"#{engine}_available?")
path = root.join("lib/decorators/#{engine}")

config.autoload_paths += path.glob('*')
config.autoload_paths += path.glob('*')

engine_context = self
config.to_prepare do
engine_context.instance_eval do
load_solidus_decorators_from(path)
engine_context = self
config.to_prepare do
engine_context.instance_eval do
load_solidus_decorators_from(path)
end
end
end
end
Expand Down