Module: SolidusSupport::EngineExtensions::ClassMethods

Defined in:
lib/solidus_support/engine_extensions.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



30
31
32
33
# File 'lib/solidus_support/engine_extensions.rb', line 30

def activate
  load_solidus_decorators_from(solidus_decorators_root)
  load_solidus_subscribers_from(solidus_subscribers_root)
end

#load_solidus_decorators_from(path) ⇒ Object

Loads decorator files.

This is needed since they are never explicitly referenced in the application code and won’t be loaded by default. We need them to be executed regardless in order to decorate existing classes.



58
59
60
61
62
# File 'lib/solidus_support/engine_extensions.rb', line 58

def load_solidus_decorators_from(path)
  path.glob('**/*.rb') do |decorator_path|
    load(decorator_path)
  end
end

#load_solidus_subscribers_from(path) ⇒ Object

Loads Solidus event subscriber files.

This allows to add event subscribers to extensions without explicitly subscribing them, similarly to what happens in Solidus core.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/solidus_support/engine_extensions.rb', line 39

def load_solidus_subscribers_from(path)
  return unless SolidusSupport::LegacyEventCompat.using_legacy?

  path.glob("**/*_subscriber.rb") do |subscriber_path|
    require_dependency(subscriber_path)
  end

  if Spree::Event.respond_to?(:activate_all_subscribers)
    Spree::Event.activate_all_subscribers
  else
    Spree::Event.subscribers.each(&:subscribe!)
  end
end