-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import SolidusSupport::EngineExtension::Decorators feature
It was added in `solidus_support` with [this PR](solidus-support-pr) and will be extracted with [this PR](extract-pr). Ref. #13 [solidus-support-pr]: solidusio/solidus_support#27 [extract-pr]: solidusio/solidus_support#28
- Loading branch information
Flavio Auciello
committed
Dec 6, 2019
1 parent
4b46885
commit a211ac1
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative 'engine_extensions/decorators' |
37 changes: 37 additions & 0 deletions
37
lib/solidus_extension_dev_tools/engine_extensions/decorators.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusExtensionDevTools | ||
module EngineExtensions | ||
module Decorators | ||
def self.included(engine) | ||
engine.class_eval do | ||
extend ClassMethods | ||
config.to_prepare(&method(:activate).to_proc) | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def activate | ||
base_path = root.join('app/decorators') | ||
|
||
if Rails.respond_to?(:autoloaders) | ||
# Add decorators folder to the Rails autoloader. This | ||
# allows Zeitwerk to resolve decorators paths correctly, | ||
# when used. | ||
Dir.glob(base_path.join('*')) do |decorators_folder| | ||
Rails.autoloaders.main.push_dir(decorators_folder) | ||
end | ||
end | ||
|
||
# Load decorator files. This is needed since they are | ||
# never explicitely referenced in the application code | ||
# and won't be loaded by default. We need them to be | ||
# executed anyway to extend exisiting classes. | ||
Dir.glob(base_path.join('**/*.rb')) do |decorator_path| | ||
Rails.configuration.cache_classes ? require(decorator_path) : load(decorator_path) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |