Skip to content

Instantly share code, notes, and snippets.

@jadon1979
Last active January 2, 2016 20:09
Show Gist options
  • Save jadon1979/8355427 to your computer and use it in GitHub Desktop.
Save jadon1979/8355427 to your computer and use it in GitHub Desktop.
devices/common/notifiers.rb devices/common/notifier.rb
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