Module: Sinatra::SubscriptionHelper

Defined in:
lib/sinatra/helpers/subscriptions.rb

Instance Method Summary collapse

Instance Method Details

#notify(creator, title, message, label, link = nil) ⇒ Object



20
21
22
23
24
# File 'lib/sinatra/helpers/subscriptions.rb', line 20

def notify(creator,title,message,label,link=nil)
  Subscription.where(:label => label).all.each do |subscription|
    notification = notify_to(subscription.user,creator,title,message,label,link)
  end
end

#notify_error(creator, title, message) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sinatra/helpers/subscriptions.rb', line 26

def notify_error(creator,title,message)
  Subscription.where(:label => 'error').all.each do |subscription|
    creator = subscription.user if creator.nil?
    notification = Notification.find(:user_id => subscription.user_id,
                                     :creator_id => creator.id,
                                     :title => title,
                                     :message => message,
                                     :label => 'error',
                                     :read_date => nil)
    if notification.nil?
      notification = notify_to(subscription.user,creator,title,message,'error')
    end
  end

end

#notify_to(user, creator, title, message, label, link = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sinatra/helpers/subscriptions.rb', line 5

def notify_to(user,creator,title,message,label,link=nil)
  notification = Notification.find_or_create(:user_id => user.id,
                              :creator_id => creator.id,
                              :title => title,
                              :message => message,
                              :label => label,
                              :link => link,
                              :creation_date => Date.today)
  if link.nil?
    notification.link = "/notifications/#{notification.id}"
    notification.save
  end
  notification
end