Skip to content

Commit

Permalink
Merge pull request #45 from nebulab/spaghetticode/autoload-subscribers
Browse files Browse the repository at this point in the history
Autoload Solidus Event subscribers from extensions
  • Loading branch information
aldesantis authored Jun 2, 2020
2 parents 04b866e + 55726cb commit c7ce0e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/solidus_support/engine_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def self.included(engine)
module ClassMethods
def activate
load_solidus_decorators_from(solidus_decorators_root)
load_solidus_subscribers_from(solidus_subscribers_root)
end

# Loads Solidus event subscriber files.
#
# This allows to add event subscribers to extensions without explicitly subscribing them,
# similarly to what happens in Solidus core.
def load_solidus_subscribers_from(path)
path.glob("**/*_subscriber.rb") do |subscriber_path|
require_dependency(subscriber_path)
end
Spree::Event.subscribers.each(&:subscribe!)
end

# Loads decorator files.
Expand All @@ -46,6 +58,13 @@ def solidus_decorators_root
root.join('app/decorators')
end

# Returns the root for this engine's Solidus event subscribers.
#
# @return [Path]
def solidus_subscribers_root
root.join("app/subscribers")
end

# Enables support for a Solidus engine.
#
# This will tell Rails to:
Expand Down

0 comments on commit c7ce0e2

Please sign in to comment.