class Eventifier::NotificationTranslator

Attributes

event[R]
options[R]
prefix[R]

Public Class Methods

new(prefix, options, *args) click to toggle source
# File lib/eventifier/notification_translator.rb, line 2
def initialize(prefix, options, *args)
  @prefix, @options = prefix, options
  @event  = ActiveSupport::Notifications::Event.new(*args).payload[:event]
end

Public Instance Methods

translate() click to toggle source
# File lib/eventifier/notification_translator.rb, line 7
def translate
  return if skip?
  users_and_relations do |user, relations|
    next if user == event.user && !options[:notify_self]
    next if skip?(user)

    Eventifier::Notification.create event: event, user: user,
      relations: relations

    Eventifier::Delivery.deliver_for user if options[:email] == :immediate
  end
end

Private Instance Methods

conditional() click to toggle source
# File lib/eventifier/notification_translator.rb, line 32
def conditional
  options[:if] || options[:unless]
end
conditional_call(*args) click to toggle source
# File lib/eventifier/notification_translator.rb, line 36
def conditional_call(*args)
  if options[:if]
    conditional.call(*args)
  else
    !conditional.call(*args)
  end
end
skip?(user = nil) click to toggle source
# File lib/eventifier/notification_translator.rb, line 24
def skip?(user = nil)
  if conditional
    !conditional_call *[event.eventable, user][0..conditional.arity-1]
  else
    false
  end
end
users_and_relations(&block) click to toggle source
# File lib/eventifier/notification_translator.rb, line 44
def users_and_relations(&block)
  Eventifier::NotificationMapping.users_and_relations event, prefix, &block
end