Class: ActiveNotify::CarrierDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/active_notify/carrier_descriptor.rb

Constant Summary collapse

RESERVED_KEYS =
%i[class_name if unless].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, notifier_class, options = {}) ⇒ CarrierDescriptor

Returns a new instance of CarrierDescriptor.



9
10
11
12
13
14
# File 'lib/active_notify/carrier_descriptor.rb', line 9

def initialize(name, notifier_class, options = {})
  @name = name
  @notifier_class = notifier_class
  @options = options.extract!(*RESERVED_KEYS)
  @args = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/active_notify/carrier_descriptor.rb', line 7

def name
  @name
end

Instance Method Details

#args(context) ⇒ Object



21
22
23
# File 'lib/active_notify/carrier_descriptor.rb', line 21

def args(context)
  @args.transform_values { |value| compute(value, context) }
end

#constantObject



16
17
18
19
# File 'lib/active_notify/carrier_descriptor.rb', line 16

def constant
  return @options[:class_name].constantize if @options[:class_name]
  @notifier_class.const_get(name.to_s.classify)
end

#deliver?(context) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/active_notify/carrier_descriptor.rb', line 25

def deliver?(context)
  return false if options.key?(:if) && !evaluate(:if, context)
  return false if options.key?(:unless) && evaluate(:unless, context)
  true
end