Class: Spree::WebhookEndpoint

Inherits:
Object
  • Object
show all
Includes:
SingleStoreResource
Defined in:
app/models/spree/webhook_endpoint.rb

Instance Method Summary collapse

Instance Method Details

#subscribed_eventsArray<String>

Returns all events this endpoint is subscribed to

Returns:

  • (Array<String>)


41
42
43
44
45
# File 'app/models/spree/webhook_endpoint.rb', line 41

def subscribed_events
  return ['*'] if subscriptions.blank?

  subscriptions
end

#subscribed_to?(event_name) ⇒ Boolean

Check if this endpoint is subscribed to a specific event

Parameters:

  • event_name (String)

    the event name to check

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/spree/webhook_endpoint.rb', line 25

def subscribed_to?(event_name)
  return true if subscriptions.blank? || subscriptions.include?('*')

  subscriptions.any? do |subscription|
    if subscription.include?('*')
      pattern = Regexp.escape(subscription).gsub('\*', '.*')
      event_name.match?(Regexp.new("^#{pattern}$"))
    else
      subscription == event_name
    end
  end
end