aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/configuration_builders/people_list.rb
blob: 7a5f3ab33b6eff32114d787953624d723a5940d2 (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
# 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", ConfigurationBuilders::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)
      name = people_list.username
      raise ArgumentError.new("Duplicate person '#{name}'") if @result.people[name]
      @result.people[name] = people_list
    end
  end
end