solidusio / solidus_support

Common runtime helpers for Solidus extensions.
BSD 3-Clause "New" or "Revised" License
9 stars 23 forks source link

Add SolidusSupport::EngineExtension::Decorators to load decorators #27

Closed kennyadsl closed 4 years ago

kennyadsl commented 4 years ago

This module is supposed to be used in extensions engines to remove boilerplate code from gem engines.

As is right now, it loads all the decorators correctly for both development and production environment, since we were having some issues with Zeitwerk not loading decorators in production.

Instructions

To use it just extend the Engine with the provided module as follow:

module SolidusExtensionName
  class Engine < Rails::Engine
    engine_name 'solidus_extension_name'
    inlcude SolidusSupport::EngineExtensions::Decorators
    # ...
  end
end

To make it work, be sure to remove the previous implementation from the Engine, that should be something like:

def self.activate
  Dir.glob(File.join(root, "app/**/*_decorator*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end
end

config.to_prepare(&method(:activate).to_proc)
kennyadsl commented 4 years ago

I've also added a bit of documentation through code comments to explain why each block is needed since they are a bit cryptic and this could help gain some time when we'll have to touch the module again.