Module: ActionMessageTexter::DeliveryMethods::ClassMethods

Defined in:
lib/action_message_texter/delivery_methods.rb

Instance Method Summary collapse

Instance Method Details

#add_delivery_method(symbol, klass, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/action_message_texter/delivery_methods.rb', line 19

def add_delivery_method(symbol, klass, options = {})
  class_attribute("#{symbol}_settings".to_sym) unless respond_to?("#{symbol}_settings".to_sym)
  send("#{symbol}_settings=".to_sym, options)
  self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
end

#wrap_delivery_behavior(message, method = nil, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_message_texter/delivery_methods.rb', line 25

def wrap_delivery_behavior(message, method = nil, options = {})
  method ||= delivery_method
  message.delivery_handler = self
  case method
  when NilClass
    raise 'Delivery method cannot be nil'
  when Symbol
    if klass = delivery_methods[method]
      message.delivery_method(klass, (send("#{method}_settings") || {}).merge(options))
    else
      raise "Invalid delivery method #{method.inspect}"
    end
  else
    message.delivery_method(method)
  end
  message.raise_delivery_errors = raise_delivery_errors
end