Module: Flyer::ControllerAdditions

Defined in:
lib/flyer/controller_additions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



27
28
29
# File 'lib/flyer/controller_additions.rb', line 27

def self.included(base)
  base.helper_method :notifications
end

Instance Method Details

#notificationsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flyer/controller_additions.rb', line 5

def notifications
  @notifications ||= begin
    found_notifications = []
    Flyer::Notification.notifications.each do |n|
      notification = Flyer::Notification.new(self)
      n.call(notification)
      notification.validate!
      if notification.visible?
        notification.used!
        found_notifications << notification.view
      end
    end

    ids = found_notifications.map(&:id)
    unless ids.uniq.count == ids.count
      raise Flyer::FoundNonUniqueIds.new
    end

    found_notifications
  end
end