Sha256: 861274f31b14331927c1cdc87b16f1a9eb89d0416a7b1da81c6808787534f13a

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

module Webhooks::Outgoing::EndpointSupport
  extend ActiveSupport::Concern
  include Webhooks::Outgoing::UriFiltering

  included do
    belongs_to BulletTrain::OutgoingWebhooks.parent_association
    belongs_to :scaffolding_absolutely_abstract_creative_concept, optional: true, class_name: "Scaffolding::AbsolutelyAbstract::CreativeConcept"

    has_many :deliveries, class_name: "Webhooks::Outgoing::Delivery", dependent: :destroy, foreign_key: :endpoint_id
    has_many :events, -> { distinct }, through: :deliveries

    scope :listening_for_event_type_id, ->(event_type_id) { where("event_type_ids @> ? OR event_type_ids = '[]'::jsonb", "\"#{event_type_id}\"") }

    validates :name, presence: true

    before_validation { url&.strip! }

    validates :url, presence: true, allowed_uri: true

    after_initialize do
      self.event_type_ids ||= []
    end

    after_save :touch_parent
  end

  def valid_event_types
    Webhooks::Outgoing::EventType.all
  end

  def creative_concepts
    team.scaffolding_absolutely_abstract_creative_concepts
  end

  def event_types
    event_type_ids.map { |id| Webhooks::Outgoing::EventType.find(id) }
  end

  def touch_parent
    send(BulletTrain::OutgoingWebhooks.parent_association).touch
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bullet_train-outgoing_webhooks-1.2.9 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.8 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.7 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.6 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.5 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.4 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.3 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.2 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.1 app/models/concerns/webhooks/outgoing/endpoint_support.rb
bullet_train-outgoing_webhooks-1.2.0 app/models/concerns/webhooks/outgoing/endpoint_support.rb