Skip to content

Commit

Permalink
Remove initializer for Rails < 6.1
Browse files Browse the repository at this point in the history
In solidusio#65 and solidusio#71
they changed how the engine is loaded using the Rails initializers.
This updates causes some issues when using Rails < 6.1 because
the initializers are totally different. The solution is to load
the extension outside of the initializer block until we use Rails 6.1
or newer version.

Ref: solidusio#73.
  • Loading branch information
MassimilianoLattanzio committed May 10, 2024
1 parent 090d8ef commit caa5d77
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/solidus_support/engine_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def solidus_subscribers_root
#
# @see #load_solidus_decorators_from
def enable_solidus_engine_support(engine)
# Starting from Rails 6.1, we can use the default gem because
# the engines are loaded in the correct way.
if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
raise 'You are using Rails 6.1 or newer, remove this fork and use the default gem instead'
end

# In the past, view and controller paths of Solidus extensions were
# added at extension loading time. As a result, if an extension
# customizing a Solidus engine is loaded before that engine
Expand All @@ -99,12 +105,15 @@ def enable_solidus_engine_support(engine)
# by those gems, we work around those gems by adding our paths before
# `initialize_cache`, which is the Rails initializer called before
# `set_load_path`.
initializer "#{name}_#{engine}_paths", before: :initialize_cache do

# In Rails < 6.1, the engines are loaded in the wrong order, so we need
# to remove the initializer below and run the code at gem's initialization.
# initializer "#{name}_#{engine}_paths", before: :initialize_cache do
if SolidusSupport.send(:"#{engine}_available?")
paths['app/controllers'] << "lib/controllers/#{engine}"
paths['app/views'] << "lib/views/#{engine}"
end
end
# end

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

0 comments on commit caa5d77

Please sign in to comment.