class Noticent::Definitions::Alert
Attributes
config[R]
constructor_name[R]
name[R]
notifiers[R]
products[R]
scope[R]
Public Class Methods
new(config, name:, scope:, constructor_name:)
click to toggle source
# File lib/noticent/definitions/alert.rb, line 13 def initialize(config, name:, scope:, constructor_name:) @config = config @name = name @scope = scope @constructor_name = constructor_name @products = Noticent::Definitions::ProductGroup.new(@config) @defaults = { _any_: Noticent::Definitions::Alert::DefaultValue.new(self, :_any_, config.default_value) } end
Public Instance Methods
applies()
click to toggle source
# File lib/noticent/definitions/alert.rb, line 60 def applies @products end
default(value, &block)
click to toggle source
# File lib/noticent/definitions/alert.rb, line 43 def default(value, &block) defaults = @defaults if block_given? default = Noticent::Definitions::Alert::DefaultValue.new(self, :_any_, value) default.instance_eval(&block) defaults[default.channel] = default else defaults[:_any_].value = value end @defaults = defaults default end
default_for(channel)
click to toggle source
# File lib/noticent/definitions/alert.rb, line 33 def default_for(channel) raise ArgumentError, "no channel named '#{channel}' found" if @config.channels[channel].nil? @defaults[channel].nil? ? @defaults[:_any_].value : @defaults[channel].value end
default_value()
click to toggle source
# File lib/noticent/definitions/alert.rb, line 39 def default_value @defaults[:_any_].value end
notify(recipient, template: '')
click to toggle source
# File lib/noticent/definitions/alert.rb, line 22 def notify(recipient, template: '') notifiers = @notifiers || {} raise BadConfiguration, "a notify is already defined for '#{recipient}'" unless notifiers[recipient].nil? alert_notifier = Noticent::Definitions::Alert::Notifier.new(self, recipient, template: template) notifiers[recipient] = alert_notifier @notifiers = notifiers alert_notifier end
validate!()
click to toggle source
# File lib/noticent/definitions/alert.rb, line 64 def validate! channels = @config.alert_channels(@name) raise BadConfiguration, "no notifiers are assigned to alert '#{@name}'" if @notifiers.nil? || @notifiers.empty? channels.each do |channel| raise BadConfiguration, "channel #{channel.name} (#{channel.klass}) has no method called #{@name}" unless channel.klass.method_defined? @name end # if a payload class is available, we can make sure it has a constructor with the name of the event raise Noticent::BadConfiguration, "payload #{@scope.payload_class} doesn't have a class method called #{name}" if @scope.check_constructor && !@scope.payload_class.respond_to?(@constructor_name) end