Class: Activities::ActivityObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
app/observers/activities/activity_observer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_subscribers(activity) ⇒ Object



17
18
19
20
21
22
# File 'app/observers/activities/activity_observer.rb', line 17

def find_subscribers(activity)
  [].tap do |subscribers|
    subscribers << User.by_role_and_context(:admin, activity.site)
    subscribers << User.by_role_and_context(:superuser, activity.site)
  end.flatten
end

.notify_subscribers(activity) ⇒ Object



11
12
13
14
15
# File 'app/observers/activities/activity_observer.rb', line 11

def notify_subscribers(activity)
  find_subscribers(activity).each do |subscriber|
    ActivityNotifier.deliver_new_content_notification(activity, subscriber) if activity.site.email_notification
  end
end

Instance Method Details

#after_create(activity) ⇒ Object



5
6
7
# File 'app/observers/activities/activity_observer.rb', line 5

def after_create(activity)
  self.class.send(:notify_subscribers, activity)
end