Module: Padrino::Mailer::Helpers::ClassMethods
- Defined in:
- padrino-mailer/lib/padrino-mailer/helpers.rb
Overview
Class methods responsible for registering mailers, configuring settings and delivering messages.
Instance Method Summary collapse
-
#deliver(mailer_name, message_name, *attributes) ⇒ Object
Delivers a mailer message email with the given attributes.
-
#email(mail_attributes = {}, &block) ⇒ Object
Delivers an email with the given mail attributes with specified and default settings.
- #inherited(subclass) ⇒ Object
-
#mailer(name, &block) ⇒ Object
(also: #mailers)
Defines a mailer object allowing the definition of various email messages that can be delivered.
-
#registered_mailers ⇒ Object
Returns all registered mailers for this application.
Instance Method Details
#deliver(mailer_name, message_name, *attributes) ⇒ Object
Delivers a mailer message email with the given attributes.
108 109 110 111 112 113 114 |
# File 'padrino-mailer/lib/padrino-mailer/helpers.rb', line 108 def deliver(mailer_name, , *attributes) mailer = registered_mailers[mailer_name] or fail "mailer '#{mailer_name}' is not registered" = mailer.[] or fail "mailer '#{mailer_name}' has no message '#{}'" = .call(*attributes) .delivery_method(*delivery_settings) .deliver end |
#email(mail_attributes = {}, &block) ⇒ Object
Delivers an email with the given mail attributes with specified and default settings.
136 137 138 139 140 141 142 143 |
# File 'padrino-mailer/lib/padrino-mailer/helpers.rb', line 136 def email(mail_attributes={}, &block) = _padrino_mailer::Message.new(self) .delivery_method(*delivery_settings) .instance_eval(&block) if block_given? mail_attributes = mailer_defaults.merge(mail_attributes) if respond_to?(:mailer_defaults) mail_attributes.each_pair { |k, v| .method(k).call(v) } .deliver end |
#inherited(subclass) ⇒ Object
56 57 58 59 |
# File 'padrino-mailer/lib/padrino-mailer/helpers.rb', line 56 def inherited(subclass) @_registered_mailers ||= {} super(subclass) end |
#mailer(name, &block) ⇒ Object Also known as: mailers
Defines a mailer object allowing the definition of various email messages that can be delivered.
86 87 88 89 90 91 |
# File 'padrino-mailer/lib/padrino-mailer/helpers.rb', line 86 def mailer(name, &block) mailer = Padrino::Mailer::Base.new(self, name, &block) mailer.delivery_settings = delivery_settings registered_mailers[name] = mailer mailer end |
#registered_mailers ⇒ Object
Returns all registered mailers for this application.
64 65 66 |
# File 'padrino-mailer/lib/padrino-mailer/helpers.rb', line 64 def registered_mailers @_registered_mailers ||= {} end |