Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload Solidus Event subscribers from extensions #45

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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