Class: Spree::Webhooks::Subscriber

Inherits:
Base
  • Object
show all
Includes:
VendorConcern
Defined in:
app/models/spree/webhooks/subscriber.rb

Class Method Summary collapse

Class Method Details

.supported_eventsObject



33
34
35
36
37
38
39
40
# File 'app/models/spree/webhooks/subscriber.rb', line 33

def self.supported_events
  Spree::Base.descendants.
    select { |model| model.included_modules.include? Spree::Webhooks::HasWebhooks }.
    to_h do |model|
    model_name = model.name.demodulize.underscore.to_sym
    [model_name, model.supported_webhook_events]
  end
end

.with_urls_for(event) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/models/spree/webhooks/subscriber.rb', line 22

def self.with_urls_for(event)
  where(
    case ActiveRecord::Base.connection.adapter_name
    when 'Mysql2'
      ["('*' MEMBER OF(subscriptions) OR ? MEMBER OF(subscriptions))", event]
    when 'PostgreSQL'
      ["subscriptions @> '[\"*\"]' OR subscriptions @> ?", [event].to_json]
    end
  )
end