aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/configuration_builders/people_list.rb
blob: fffa15cad6ed9147617327072f6cd5aa8e446d54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# encoding: UTF-8
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

      def created_notification(notification)
        @result.notifications ||= []
        @result.notifications << notification
      end

    end
  end

  class ConfigurationBuilder < ObjectBuilder

    is_builder "people_list", ConfigurationBuilders::PeopleList

    # Method called once a people_list has been created to check for duplicate labels
    #
    # @param [Mauve::PeopleList] people_list
    #
    def created_people_list(people_list)
      label = people_list.label
      if @result.people_lists.has_key?(label)
        _logger.warn("Duplicate people_list '#{label}'") 
        @result.people_lists[label] += people_list.list
      else
        @result.people_lists[label] = people_list
      end
    end

  end
end