Last active
January 2, 2016 20:09
-
-
Save jadon1979/8355427 to your computer and use it in GitHub Desktop.
devices/common/notifiers.rb
devices/common/notifier.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Devices | |
module Common | |
class Reports < Devices::Common::Notifiers; end | |
class Warnings < Devices::Common::Notifiers; end | |
class Errors < Devices::Common::Notifiers; end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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