Class: Noticent::Definitions::Alert::Notifier
- Inherits:
-
Object
- Object
- Noticent::Definitions::Alert::Notifier
- Defined in:
- lib/noticent/definitions/alert.rb
Overview
holds a list of recipient + channel
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
channel to be notified.
-
#channel_group ⇒ Object
readonly
group to be notified.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#applicable_channels ⇒ Object
returns an array of all channels this notifier should send to.
-
#initialize(alert, recipient, template: '') ⇒ Notifier
constructor
A new instance of Notifier.
- #on(channel_group_or_name) ⇒ Object
Constructor Details
#initialize(alert, recipient, template: '') ⇒ Notifier
Returns a new instance of Notifier.
83 84 85 86 87 88 89 90 |
# File 'lib/noticent/definitions/alert.rb', line 83 def initialize(alert, recipient, template: '') @recipient = recipient @alert = alert @config = alert.config @template = template @channel_group = :default @channel = nil end |
Instance Attribute Details
#channel ⇒ Object (readonly)
channel to be notified
80 81 82 |
# File 'lib/noticent/definitions/alert.rb', line 80 def channel @channel end |
#channel_group ⇒ Object (readonly)
group to be notified
79 80 81 |
# File 'lib/noticent/definitions/alert.rb', line 79 def channel_group @channel_group end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
78 79 80 |
# File 'lib/noticent/definitions/alert.rb', line 78 def recipient @recipient end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
81 82 83 |
# File 'lib/noticent/definitions/alert.rb', line 81 def template @template end |
Instance Method Details
#applicable_channels ⇒ Object
returns an array of all channels this notifier should send to
108 109 110 111 112 113 114 115 |
# File 'lib/noticent/definitions/alert.rb', line 108 def applicable_channels if @channel_group == :_none_ # it's a single channel [@channel] else @config.channels_by_group(@channel_group) end end |
#on(channel_group_or_name) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/noticent/definitions/alert.rb', line 92 def on(channel_group_or_name) # is it a group or a channel name? if @config.channel_groups.include? channel_group_or_name # it's a group @channel_group = channel_group_or_name @channel = nil elsif !@config.channels[channel_group_or_name].nil? @channel_group = :_none_ @channel = @config.channels[channel_group_or_name] else # not a group and not a channel raise ArgumentError, "no channel or channel group found named '#{channel_group_or_name}'" end end |