Class: UserNotifier

Inherits:
Object
  • Object
show all
Defined in:
app/workers/user_notifier.rb

Overview

This plain ruby class should handle all user notifications, called by various models

Class Method Summary collapse

Class Method Details

.finished_order(args) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/workers/user_notifier.rb', line 11

def self.finished_order(args)
  order_id = args.first
  Order.find(order_id).group_orders.each do |group_order|
    next if group_order.ordergroup.nil?
    group_order.ordergroup.users.each do |user|
      if user.settings.notify['order_finished']
        Mailer.deliver_now_with_user_locale user do
          Mailer.order_result(user, group_order)
        end
      end
    end
  end
end

.negative_balance(args) ⇒ Object

If this order group's account balance is made negative by the given/last transaction, a message is sent to all users who have enabled notification.


27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/workers/user_notifier.rb', line 27

def self.negative_balance(args)
  ordergroup_id, transaction_id = args
  transaction = FinancialTransaction.find transaction_id

  Ordergroup.find(ordergroup_id).users.each do |user|
    if user.settings.notify['negative_balance']
      Mailer.deliver_now_with_user_locale user do
        Mailer.negative_balance(user, transaction)
      end
    end
  end
end

.perform(foodcoop, method_name, *args) ⇒ Object

Resque style method to perform every class method defined here


6
7
8
9
# File 'app/workers/user_notifier.rb', line 6

def self.perform(foodcoop, method_name, *args)
  FoodsoftConfig.select_foodcoop(foodcoop) if FoodsoftConfig[:multi_coop_install]
  self.send method_name, args
end