module Communique

communique external methods

top level gem module

gem version

Constants

VERSION

Attributes

config[RW]

Public Class Methods

actions() click to toggle source
# File lib/communique.rb, line 29
def self.actions
  Action.all.to_a
end
configure() { |config| ... } click to toggle source
# File lib/communique/configuration.rb, line 7
def self.configure
  self.config ||= Configuration.new
  yield config if block_given?
end
count_unseen(notifiable) click to toggle source
# File lib/communique.rb, line 41
def self.count_unseen(notifiable)
  Notification.count_unseen notifiable
end
notify(notifiable, action_key, context_info = nil) click to toggle source
# File lib/communique.rb, line 10
def self.notify(notifiable, action_key, context_info = nil)
  action = Action.find_or_create_by(key: action_key)

  if prevent_unseen_duplicates?
    existing_notification = find_existing_notifications(notifiable, action_key)
    if existing_notification
      existing_notification.update_attributes(
        context_info: context_info,
        updated_at: Time.now
      )
      return existing_notification.id.to_s
    end
  end
  notification = create_notification(notifiable, context_info, action_key, action)
  Handler.external_services notification

  notification.id.to_s
end
viewed!(notifiable, seen_notification_ids) click to toggle source
# File lib/communique.rb, line 37
def self.viewed!(notifiable, seen_notification_ids)
  Notification.viewed! notifiable, seen_notification_ids
end
viewed_all!(notifiable) click to toggle source
# File lib/communique.rb, line 33
def self.viewed_all!(notifiable)
  Notification.viewed_all!(notifiable)
end

Private Class Methods

create_notification( notifiable, context_info, action_key, action) click to toggle source
# File lib/communique.rb, line 57
def self.create_notification( notifiable, context_info, action_key, action)
  Notification.create(
    notifiable: notifiable,
    context_info: context_info,
    action_key: action_key,
    action: action
  )
end
find_existing_notifications(notifiable, action_key) click to toggle source
# File lib/communique.rb, line 49
def self.find_existing_notifications(notifiable, action_key)
  Notification.where(
    notifiable: notifiable,
    action_key: action_key,
    seen: false
  ).order_by(updated_at: :desc).first
end
prevent_unseen_duplicates?() click to toggle source
# File lib/communique.rb, line 45
def self.prevent_unseen_duplicates?
  !Communique.config.nil? && Communique.config.prevent_unseen_duplicates
end