Class: StandardCircuit::Mailer::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/standard_circuit/mailer/delivery_method.rb

Class Method Summary collapse

Class Method Details

.install(mailer_class) ⇒ Object

ActionMailer’s ‘add_delivery_method` unconditionally resets `<symbol>_settings` to its `default_options` arg. If the host app has already registered :standard_circuit (e.g. from its own `on_load(:action_mailer)` block in an env file, queued earlier), calling `add_delivery_method` again would wipe the settings the app just wrote — causing `KeyError: key not found: :circuit` at delivery time. Skip if already registered. (This guard assumes the host app registers first; if you call `add_delivery_method` from `after_initialize` or otherwise after the gem’s Railtie hook fires, use ‘standard_circuit_settings=` directly to avoid the reset.)



63
64
65
66
67
# File 'lib/standard_circuit/mailer/delivery_method.rb', line 63

def self.install(mailer_class)
  return if mailer_class.delivery_methods.key?(:standard_circuit)

  mailer_class.add_delivery_method :standard_circuit, StandardCircuit::Mailer::DeliveryMethod
end