module Async::Messaging::Controller

Public Class Methods

included(base) click to toggle source

controller helper

# File lib/async-messaging/controller.rb, line 18
def self.included(base)
  base.before_filter :help_async_messaging
end

Public Instance Methods

help_async_messaging() click to toggle source

before filter that creates flash messages

# 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) click to toggle source

collect all flash notifications from a given user

# 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