Module: Async::Messaging::Controller

Defined in:
lib/async-messaging/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

controller helper



18
19
20
# File 'lib/async-messaging/controller.rb', line 18

def self.included(base)
  base.before_filter :help_async_messaging
end

Instance Method Details

#help_async_messagingObject

before filter that creates flash messages



22
23
24
25
26
27
# File 'lib/async-messaging/controller.rb', line 22

def help_async_messaging
  # push flash_notices to flash.now
  flash_notices = notify_flash(User.current).flat_map(&:to_h)
  flash.now[:async_messaging] ||= []
  flash.now[:async_messaging].concat flash_notices
end

#notify_flash(user) ⇒ Object

collect all flash notifications from a given user



6
7
8
9
10
11
12
13
14
15
# File 'lib/async-messaging/controller.rb', line 6

def notify_flash(user)
  return if user.nil?
  rs = Mongoid::Message.where(to: user.id, category: :flash)
  # collect results (copy)
  ret = rs.to_a
  # remove from the database
  rs.delete_all
  # return the collected results
  ret
end