Skip to content

Commit 223cc77

Browse files
Merge pull request #182 from solidusio/feature/remove-conditional-loading
Adopt conditional code loading from solidus_support
2 parents a78264a + d4f78e6 commit 223cc77

1 file changed

Lines changed: 4 additions & 42 deletions

File tree

lib/spree/auth/engine.rb

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
module Spree
77
module Auth
88
class Engine < Rails::Engine
9+
include SolidusSupport::EngineExtensions
10+
911
isolate_namespace Spree
1012
engine_name 'solidus_auth'
1113

@@ -18,42 +20,12 @@ class Engine < Rails::Engine
1820
end
1921

2022
config.to_prepare do
21-
auth = Spree::Auth::Engine
22-
23-
if SolidusSupport.backend_available?
24-
auth.load_decorators_for('backend')
25-
auth.prepare_backend
26-
end
27-
28-
if SolidusSupport.frontend_available?
29-
auth.load_decorators_for('frontend')
30-
auth.prepare_frontend
31-
end
23+
Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available?
24+
Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available?
3225

3326
ApplicationController.include Spree::AuthenticationHelpers
3427
end
3528

36-
def self.load_decorators_for(component_name)
37-
base_path = root.join('lib/decorators', component_name)
38-
39-
if Rails.respond_to?(:autoloaders) && Rails.autoloaders.main
40-
# Add decorators folder to the Rails autoloader. This
41-
# allows Zeitwerk to resolve decorators paths correctly,
42-
# when used.
43-
base_path.glob('*') do |decorators_folder|
44-
Rails.autoloaders.main.push_dir(decorators_folder)
45-
end
46-
end
47-
48-
# Load decorator files. This is needed since they are
49-
# never explicitely referenced in the application code
50-
# and won't be loaded by default. We need them to be
51-
# executed anyway to extend exisiting classes.
52-
base_path.glob('**/*_decorator*.rb') do |decorator_path|
53-
require_dependency(decorator_path)
54-
end
55-
end
56-
5729
def self.prepare_backend
5830
Spree::Admin::BaseController.unauthorized_redirect = -> do
5931
if try_spree_current_user
@@ -77,16 +49,6 @@ def self.prepare_frontend
7749
end
7850
end
7951
end
80-
81-
if SolidusSupport.backend_available?
82-
paths["app/controllers"] << "lib/controllers/backend"
83-
paths["app/views"] << "lib/views/backend"
84-
end
85-
86-
if SolidusSupport.frontend_available?
87-
paths["app/controllers"] << "lib/controllers/frontend"
88-
paths["app/views"] << "lib/views/frontend"
89-
end
9052
end
9153
end
9254
end

0 commit comments

Comments
 (0)