Skip to content

Commit

Permalink
Fix dependency on the engines load order when adding paths
Browse files Browse the repository at this point in the history
We were adding the view and controller paths at engine loading time. So,
E.g., if a frontend engine was present, but we loaded it after the
extension depending on `solidus_support` (i.e., the extension went first
on the `Gemfile`), paths weren't being loaded.

We're adding the paths on an initializer that runs before Rails's
[`:initialize_dependency_mechanism`](https://github.com/rails/rails/blob/127dd06df66552dd272eea7832f8bb205cf6fd01/railties/lib/rails/application/bootstrap.rb#L68)
one. Thenceforth Rails begins messing with the load paths, and it doesn't
take them into account anymore.

Keep in mind that the `SolidusSupport.#{engine}_available?` call needs
to be placed within the `initializer` context and not wrapping it. The
reason is the same as above: don't doing the logic at load time.
  • Loading branch information
waiting-for-dev committed Jun 16, 2021
1 parent 09bfde4 commit 202e77c
Showing 1 changed file with 17 additions and 11 deletions.
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?")
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

0 comments on commit 202e77c

Please sign in to comment.