diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-23 16:01:44 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-23 16:01:44 +0100 |
commit | 6561f886ed03a79ca035a1733816ab97380576d2 (patch) | |
tree | 24282c1a9f85a6a1f1eb010df7c421f3c08315bb /lib/mauve/configuration_builders | |
parent | ca99b0dff974d2fc841d7132d03b3ad1d1bf9b1e (diff) |
Persons/PeopleLists can now specify multiple notification preferences.
Diffstat (limited to 'lib/mauve/configuration_builders')
-rw-r--r-- | lib/mauve/configuration_builders/alert_group.rb | 29 | ||||
-rw-r--r-- | lib/mauve/configuration_builders/people_list.rb | 17 | ||||
-rw-r--r-- | lib/mauve/configuration_builders/person.rb | 18 |
3 files changed, 56 insertions, 8 deletions
diff --git a/lib/mauve/configuration_builders/alert_group.rb b/lib/mauve/configuration_builders/alert_group.rb index 40e5d9d..851ab7f 100644 --- a/lib/mauve/configuration_builders/alert_group.rb +++ b/lib/mauve/configuration_builders/alert_group.rb @@ -19,7 +19,10 @@ module Mauve # # @return [Mauve::Notification] New notification instance. def builder_setup(who) - who = if @context.people[who] + who = if who.is_a?(Mauve::Person) or who.is_a?(Mauve::PeopleList) + who + + elsif @context.people[who] @context.people[who] elsif @context.people_lists[who] @@ -29,7 +32,8 @@ module Mauve raise ArgumentError.new("You have not declared who #{who} is") end - @result = Mauve::Notification.new(who, @context.last_alert_group.level) + + @result = Mauve::Notification.new(who) end is_attribute "every" @@ -47,7 +51,6 @@ module Mauve # @return [Mauve::AlertGroup] New alert group instance def builder_setup(name="anonymous_name") @result = Mauve::AlertGroup.new(name) - @context.last_alert_group = @result end is_block_attribute "includes" @@ -62,7 +65,25 @@ module Mauve # def created_notify(notification) @result.notifications ||= [] - @result.notifications << notification + + if notification.during.nil? and notification.every.nil? + @result.notifications += notification.person.notifications.collect do |n| + # + # Set up a new notification for each one defined for this person. + # + new_notification = Mauve::Notification.new(notification.person) + new_notification.level = @result.level + new_notification.every = n.every + new_notification.during = n.during + new_notification + end + else + # + # Set the level for this notification + # + notification.level = @result.level + @result.notifications << notification + end end end diff --git a/lib/mauve/configuration_builders/people_list.rb b/lib/mauve/configuration_builders/people_list.rb index e5f6715..fffa15c 100644 --- a/lib/mauve/configuration_builders/people_list.rb +++ b/lib/mauve/configuration_builders/people_list.rb @@ -2,19 +2,32 @@ require 'object_builder' require 'mauve/people_list' require 'mauve/configuration_builder' +require 'mauve/configuration_builders/alert_group' module Mauve module ConfigurationBuilders class PeopleList < ObjectBuilder + is_builder "notification", Notification + def builder_setup(label, list) @result = Mauve::PeopleList.new(label) @result += list + @result + end + + # + # Notify is a shortcut for "notification" + # + def notify(&block) + notification(@result, &block) end - is_block_attribute "during" - is_attribute "every" + def created_notification(notification) + @result.notifications ||= [] + @result.notifications << notification + end end end diff --git a/lib/mauve/configuration_builders/person.rb b/lib/mauve/configuration_builders/person.rb index 7881d01..dff6f85 100644 --- a/lib/mauve/configuration_builders/person.rb +++ b/lib/mauve/configuration_builders/person.rb @@ -2,6 +2,7 @@ require 'object_builder' require 'mauve/person' require 'mauve/configuration_builder' +require 'mauve/configuration_builders/alert_group' module Mauve module ConfigurationBuilders @@ -12,11 +13,11 @@ module Mauve @result = Mauve::Person.new(username) end + is_builder "notification", Notification + is_block_attribute "urgent" is_block_attribute "normal" is_block_attribute "low" - is_block_attribute "during" - is_attribute "every" is_attribute "password" is_attribute "sms" is_attribute "holiday_url" @@ -29,6 +30,18 @@ module Mauve # @param [Block] block def all(&block); urgent(&block); normal(&block); low(&block); end + # + # Notify is a shortcut for "notification" + # + def notify(&block) + notification(@result, &block) + end + + def created_notification(notification) + @result.notifications ||= [] + @result.notifications << notification + end + # Notification suppression hash # # @param [Hash] h @@ -41,6 +54,7 @@ module Mauve @result.notification_thresholds[v] = Array.new(k) end end + end end |