Module: Hertz::Notifiable

Defined in:
lib/hertz/notifiable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/hertz/notifiable.rb', line 4

def self.included(base)
  base.class_eval do
    has_many :notifications,
      class_name: 'Hertz::Notification',
      as: :receiver,
      inverse_of: :receiver,
      dependent: :destroy
  end
end

Instance Method Details

#notify(notification_or_klass, meta = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hertz/notifiable.rb', line 14

def notify(notification_or_klass, meta = {})
  notification = if notification_or_klass.is_a?(Class)
    notification_or_klass.new(meta: meta)
  else
    notification_or_klass
  end

  notification.receiver = self

  notifications << notification
end