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 a090359
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/lib/spree/event/subscriber.rb
Expand Up @@ -54,7 +54,16 @@ def self.included(base)
# end
# end
def event_action(method_name, event_name: nil)
mattr_accessor "#{method_name}_handler"
mattr_writer "#{method_name}_handler"

module_eval do
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
end

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

Expand All @@ -67,6 +76,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 a090359

Please sign in to comment.