Skip to content

Commit

Permalink
Deprecate old event mappings methods
Browse files Browse the repository at this point in the history
We're keeping the old event mappings handler methods, as somebody may
still be relying on them, but they're now deprecated.
  • Loading branch information
spaghetticode committed Sep 25, 2020
1 parent 1304862 commit 1bbe5b1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/lib/spree/event/subscriber.rb
Expand Up @@ -54,7 +54,14 @@ def self.included(base)
# end
# end
def event_action(method_name, event_name: nil)
mattr_accessor "#{method_name}_handler"
mattr_writer "#{method_name}_handler"

define_method "#{method_name}_handler" do
Spree::Deprecation.warn("#{name}.#{method_name}_handler and #{name}.#{method_name}_handler= from the old events mapping interface are deprecated. Please use the new mapping stored in Spree::Event.subscribers.", caller)

class_variable_get("@@#{method_name}_handler")
end

event_actions[method_name] = (event_name || method_name).to_s
end

Expand All @@ -67,6 +74,9 @@ def subscribe!
unsubscribe!
event_actions.each do |event_action, event_name|
subscription = Spree::Event.subscribe(event_name) { |event| send event_action, event }
# old mappings, to be removed when Solidus 2.10 is not supported anymore:
send "#{event_action}_handler=", subscription
# new mappings:
Spree::Event.subscribers[name][event_action] = subscription
end
end
Expand Down

0 comments on commit 1bbe5b1

Please sign in to comment.