Sha256: 8519ff1c7fefa0ad41d4254fe87a6fb265d54874eb07be550e8ae44ca6b63798

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8
module Sinatra
  module SubscriptionHelper

    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

    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

    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
  end

  helpers SubscriptionHelper
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sinatra-hexacta-0.3.7 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.6 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.5 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.4 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.3 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.2 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.1 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.3.0 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.1.1 lib/sinatra/helpers/subscriptions.rb
sinatra-hexacta-0.1.0 lib/sinatra/helpers/subscriptions.rb