Class: Spree::Webhooks::Subscriber

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.supported_eventsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/spree/webhooks/subscriber.rb', line 45

def self.supported_events
  @supported_events ||= begin
    Rails.application.eager_load! if Rails.env.development?
    Spree::Base.descendants.
      select { |model| model.included_modules.include? Spree::Webhooks::HasWebhooks }.
      sort_by { |model| model.name.demodulize.underscore }.
      to_h do |model|
        model_name = model.name.demodulize.underscore.to_sym
        [model_name, model.supported_webhook_events]
      end
  end
end

.with_urls_for(event) ⇒ Object



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

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]
    when 'SQLite'
      ["subscriptions LIKE '%\"*\"%' OR subscriptions LIKE ?", "%#{event}%"]
    end
  )
end

Instance Method Details

#latest_event_atObject



28
29
30
# File 'app/models/spree/webhooks/subscriber.rb', line 28

def latest_event_at
  events.order(:created_at).last&.created_at
end