Module: SolidusSupport::EngineExtensions::Decorators::ClassMethods

Defined in:
lib/solidus_support/engine_extensions/decorators.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solidus_support/engine_extensions/decorators.rb', line 14

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