Sha256: 58cd82562789f3f27d72a497b776e76e4baa79005f6f9e19c73d0f48dc9c58e0

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module SolidusSupport
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_support-0.4.0 lib/solidus_support/engine_extensions/decorators.rb