aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/person.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-09 18:09:52 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-09 18:09:52 +0100
commit495c44445642cfae8f23fadde299ad5307f5be58 (patch)
tree0104c9eef164235aa5ab05b126c8f63e52fb8624 /lib/mauve/person.rb
parent0c88fcc91db1b003cd5d5311f62700c7867b4099 (diff)
Big commit
--HG-- rename : views/please_authenticate.haml => views/login.haml
Diffstat (limited to 'lib/mauve/person.rb')
-rw-r--r--lib/mauve/person.rb45
1 files changed, 35 insertions, 10 deletions
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index da3aa13..42b6baf 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -3,7 +3,7 @@ require 'timeout'
require 'log4r'
module Mauve
- class Person < Struct.new(:username, :password, :holiday_url, :urgent, :normal, :low)
+ class Person < Struct.new(:username, :password, :holiday_url, :urgent, :normal, :low, :email, :xmpp, :sms)
attr_reader :notification_thresholds
@@ -24,26 +24,50 @@ module Mauve
#
class NotificationCaller
- def initialize(alert, other_alerts, notification_methods, base_conditions={})
- logger = Log4r::Logger.new "mauve::NotificationCaller"
+ def initialize(person, alert, other_alerts, notification_methods, base_conditions={})
+ @person = person
@alert = alert
@other_alerts = other_alerts
@notification_methods = notification_methods
@base_conditions = base_conditions
end
- def method_missing(name, destination, *args)
- conditions = @base_conditions.merge(args[0] ? args[0] : {})
- notification_method = @notification_methods[name.to_s]
+ def logger ; @logger ||= Log4r::Logger.new self.class.to_s ; end
+
+ #
+ # This method makes sure things liek
+ #
+ # xmpp
+ # works
+ #
+ def method_missing(name, *args)
+ #
+ # Work out the destination
+ #
+ if args.first.is_a?(String)
+ destination = args.pop
+ else
+ destination = @person.__send__(name)
+ end
- unless notification_method
- raise NoMethodError.new("#{name} not defined as a notification method")
+ if args.first.is_a?(Array)
+ conditions = @base_conditions.merge(args[0])
end
+
+ notification_method = Configuration.current.notification_methods[name.to_s]
+
+ raise NoMethodError.new("#{name} not defined as a notification method") unless notification_method
+
# Methods are expected to return true or false so the user can chain
# them together with || as fallbacks. So we have to catch exceptions
# and turn them into false.
#
- notification_method.send_alert(destination, @alert, @other_alerts, conditions)
+ res = notification_method.send_alert(destination, @alert, @other_alerts, conditions)
+ #
+ # Log the result
+ logger.debug "Notification " + (res ? "succeeded" : "failed" ) + " for #{@person.username} using notifier '#{name}' to '#{destination}'"
+
+ res
end
end
@@ -174,6 +198,7 @@ module Mauve
return if suppressed? or this_alert_suppressed
result = NotificationCaller.new(
+ self,
alert,
current_alerts,
Configuration.current.notification_methods,
@@ -197,7 +222,7 @@ module Mauve
# Returns the subset of current alerts that are relevant to this Person.
#
def current_alerts
- Alert.all_current.select do |alert|
+ Alert.all_raised.select do |alert|
my_last_update = AlertChanged.first(:person => username, :alert_id => alert.id)
my_last_update && my_last_update.update_type != :cleared
end