Module: Spree::StockLevel::CustomEvents
- Included in:
- Spree::StockLevel
- Defined in:
- app/models/spree/stock_level/custom_events.rb
Overview
Dual-emits the pre-6.0 stock_item.* lifecycle events beside the
stock_level.* ones, so a webhook endpoint a merchant configured against
the old names keeps receiving deliveries. Removed in 6.5,
the same way Fulfillment::CustomEvents carries shipment.*.
The twins are written here rather than as an option on
Publishable because one rename does not need generic machinery
on a concern every Spree model includes — and rather than in the
Spree::StockItem alias file because that is autoloaded lazily, which
would leave the events firing in production and silently not in
development.
Constant Summary collapse
- LEGACY_EVENT_PREFIX =
'stock_item'- LEGACY_EVENT_SUFFIXES =
%w[created updated deleted].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#publish_event(event_name, payload = nil, metadata = {}) ⇒ Object
Wraps publishing rather than the three callbacks that call it, so the decisions Publishable makes — whether events are enabled at all, whether a touch-only update is worth announcing — are made once and the legacy twin simply follows whatever the new name did.
Class Method Details
.included(base) ⇒ Object
20 21 22 23 24 |
# File 'app/models/spree/stock_level/custom_events.rb', line 20 def self.included(base) LEGACY_EVENT_SUFFIXES.each do |suffix| base.publishes_event("#{LEGACY_EVENT_PREFIX}.#{suffix}", deprecated_alias_of: "#{base.event_prefix}.#{suffix}") end end |
Instance Method Details
#publish_event(event_name, payload = nil, metadata = {}) ⇒ Object
Wraps publishing rather than the three callbacks that call it, so the decisions Publishable makes — whether events are enabled at all, whether a touch-only update is worth announcing — are made once and the legacy twin simply follows whatever the new name did.
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/spree/stock_level/custom_events.rb', line 30 def publish_event(event_name, payload = nil, = {}) published = super legacy_name = legacy_event_name(event_name) return published if legacy_name.nil? super(legacy_name, payload, ) published end |