lib/webhook_system/subscription.rb in webhook_system-2.4.0 vs lib/webhook_system/subscription.rb in webhook_system-2.4.1

- old
+ new

@@ -6,25 +6,25 @@ class Subscription < ActiveRecord::Base self.table_name = 'webhook_subscriptions' belongs_to :account if defined?(Account) - INLINE_JOB_REGEXP=/^inline:(.*)/ - validates :url, presence: true, url: { no_local: true }, if: Proc.new { |a| !a.url.match?(INLINE_JOB_REGEXP) } + INLINE_JOB_REGEXP = /^inline:(.*)/.freeze + validates :url, presence: true, url: { no_local: true }, if: proc { |a| !a.url.match?(INLINE_JOB_REGEXP) } validates :secret, presence: true has_many :topics, class_name: 'WebhookSystem::SubscriptionTopic', dependent: :destroy has_many :event_logs, class_name: 'WebhookSystem::EventLog', dependent: :delete_all accepts_nested_attributes_for :topics, allow_destroy: true scope :active, -> { where(active: true) } - scope :for_topic, -> (topic) { + scope :for_topic, ->(topic) { joins(:topics).where(WebhookSystem::SubscriptionTopic.table_name => { name: topic }) } - scope :interested_in_topic, -> (topic) { active.for_topic(topic) } + scope :interested_in_topic, ->(topic) { active.for_topic(topic) } # Main invocation point for dispatching events, can either be called on the class # or on a relation (ie a scoped down list of subs), will find applicable subs and dispatch to them # # @param [WebhookSystem::BaseEvent] event The Event Object @@ -57,10 +57,10 @@ topics.each do |topic| new_topics_attributes << { id: topic.id, name: topic.name, - _destroy: !new_topics.include?(topic.name), + _destroy: new_topics.exclude?(topic.name), } end new_topics_attributes += add_topics.map { |topic| { name: topic } }