lib/city_watch/util/alerts.rb in city-watch-0.5.4 vs lib/city_watch/util/alerts.rb in city-watch-0.5.5

- old
+ new

@@ -1,36 +1,29 @@ module Alerts - module ClassMethods - - def send_alert(message,dat=nil) - CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time}) - end - def alerts - @alerts ||= [] - if block_given? - @alerts.each do |a| - yield a - end - else - @alerts + def send_alert(message,dat=nil) + CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time}) + end + + def alerts + @alerts ||= [] + if block_given? + @alerts.each do |a| + yield a end - nil + else + @alerts end - - def get_alerts(host=host,num=5) - CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1 - end - - def send_alerts! - get_alerts.map do |alert| - puts "Alert: #{alert.inspect}" if CityWatch.debug? - end - end - + nil end - - def self.included(base) - base.extend(ClassMethods) + + def get_alerts(host=host,num=5) + CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1 + end + + def send_alerts! + get_alerts.map do |alert| + puts "Alert: #{alert.inspect}" if CityWatch.debug? + end end end \ No newline at end of file