Module: Hanami::Mailer
- Includes:
- Utils::ClassAttribute
- Defined in:
- lib/hanami/mailer.rb,
lib/hanami/mailer/dsl.rb,
lib/hanami/mailer/version.rb,
lib/hanami/mailer/template.rb,
lib/hanami/mailer/configuration.rb,
lib/hanami/mailer/rendering/template_name.rb,
lib/hanami/mailer/rendering/templates_finder.rb
Overview
Hanami::Mailer
Defined Under Namespace
Modules: ClassMethods, Dsl, Rendering Classes: Configuration, Error, MissingDeliveryDataError, Template
Constant Summary collapse
- CONTENT_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Content types mapping
{ html: "text/html", txt: "text/plain" }.freeze
- VERSION =
"1.3.3"
Class Method Summary collapse
-
.configure(&blk) ⇒ Object
Configure the framework.
-
.deliveries ⇒ Array
Test deliveries.
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
-
.load! ⇒ Object
private
Load the framework.
Instance Method Summary collapse
-
#deliver ⇒ Object
private
Delivers a multipart email, by looking at all the associated templates and render them.
-
#initialize(locals = {}) ⇒ Object
Initialize a mailer.
-
#render(format) ⇒ String
private
Render a single template with the specified format.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
279 280 281 |
# File 'lib/hanami/mailer.rb', line 279 def method_missing(method_name) @locals.fetch(method_name) { super } end |
Class Method Details
.configure(&blk) ⇒ Object
Configure the framework. It yields the given block in the context of the configuration
65 66 67 68 |
# File 'lib/hanami/mailer.rb', line 65 def self.configure(&blk) configuration.instance_eval(&blk) self end |
.deliveries ⇒ Array
Test deliveries
This is a collection of delivered messages, used when delivery_method
is set on :test
118 119 120 |
# File 'lib/hanami/mailer.rb', line 118 def self.deliveries Mail::TestMailer.deliveries end |
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules. It includes basic Hanami::Mailer modules to the given Class. It sets a copy of the framework configuration
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/hanami/mailer.rb', line 80 def self.included(base) conf = configuration conf.add_mailer(base) base.class_eval do extend Dsl extend ClassMethods include Utils::ClassAttribute class_attribute :configuration self.configuration = conf.duplicate end conf.copy!(base) end |
.load! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the framework
126 127 128 129 |
# File 'lib/hanami/mailer.rb', line 126 def self.load! Mail.eager_autoload! configuration.load! end |
Instance Method Details
#deliver ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delivers a multipart email, by looking at all the associated templates and render them.
233 234 235 236 237 238 239 |
# File 'lib/hanami/mailer.rb', line 233 def deliver mail.deliver rescue ArgumentError => exception raise MissingDeliveryDataError if exception. =~ /SMTP (From|To) address/ raise end |
#initialize(locals = {}) ⇒ Object
Initialize a mailer
209 210 211 212 213 214 215 |
# File 'lib/hanami/mailer.rb', line 209 def initialize(locals = {}) @locals = locals @format = locals.fetch(:format, nil) @charset = locals.fetch(:charset, self.class.configuration.default_charset) @mail = build prepare end |
#render(format) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render a single template with the specified format.
225 226 227 |
# File 'lib/hanami/mailer.rb', line 225 def render(format) self.class.templates(format).render(self, @locals) end |