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.2'.freeze
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.
270 271 272 |
# File 'lib/hanami/mailer.rb', line 270 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
63 64 65 66 |
# File 'lib/hanami/mailer.rb', line 63 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
116 117 118 |
# File 'lib/hanami/mailer.rb', line 116 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/hanami/mailer.rb', line 78 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
124 125 126 127 |
# File 'lib/hanami/mailer.rb', line 124 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.
224 225 226 227 228 229 230 |
# File 'lib/hanami/mailer.rb', line 224 def deliver mail.deliver rescue ArgumentError => exception raise MissingDeliveryDataError if exception. =~ /SMTP (From|To) address/ raise end |
#initialize(locals = {}) ⇒ Object
Initialize a mailer
200 201 202 203 204 205 206 |
# File 'lib/hanami/mailer.rb', line 200 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.
216 217 218 |
# File 'lib/hanami/mailer.rb', line 216 def render(format) self.class.templates(format).render(self, @locals) end |