Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from jadon1979/notifications.rb
Created June 22, 2014 21:38
Show Gist options
  • Save kivanio/b0ecdec559a7fc165c8a to your computer and use it in GitHub Desktop.
Save kivanio/b0ecdec559a7fc165c8a to your computer and use it in GitHub Desktop.
module Devices
module Common
class Reports < Devices::Common::Notifiers; end
class Warnings < Devices::Common::Notifiers; end
class Errors < Devices::Common::Notifiers; end
end
end
module Devices
module Common
class Notifier
attr_accessor :message, :sender, :level
def initialize(*params)
@message, @sender, @level = params
@message = Rails.env == "development" ? "#{@sender} - #{@message}" : "#{@message}"
end
end
end
end
module Devices
module Common
class Notifiers
include Enumerable
def initialize
@notifications = []
end
def <<(val)
@notifications << val
end
def each(&block)
@notifications.each(&block)
end
def empty?
@notifications.count == 0
end
def add(msg, level = 1)
sender = "#{caller[0].to_s}"
@notifications << Devices::Common::Notifier.new(msg, sender, level)
end
def concat(ary)
ary.each do |notification|
@notifications << notification
end
end
def clear()
@notifications = []
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment