Module: AutoAlert::ActsAsAlert::ClassMethods

Defined in:
lib/auto_alert/acts_as_alert.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_alertObject

Class method to register a model as alertable



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/auto_alert/acts_as_alert.rb', line 7

def acts_as_alert
  belongs_to :alertable, polymorphic: true
  scope :resolved, -> { where(resolved: true) }
  scope :unresolved, -> { where(resolved: false) }

  validates :kind,
    uniqueness: {
      scope: :alertable,
      message: ->(record, data) { "This #{record.alertable_type} already has a '#{data[:value]}' alert." },
    }
  include AutoAlert::ActsAsAlert::LocalInstanceMethods
  extend AutoAlert::ActsAsAlert::SingletonMethods
end