Module: Lotus::Mailer
- Includes:
- Utils::ClassAttribute
- Defined in:
- lib/lotus/mailer.rb,
lib/lotus/mailer/dsl.rb,
lib/lotus/mailer/version.rb,
lib/lotus/mailer/template.rb,
lib/lotus/mailer/configuration.rb,
lib/lotus/mailer/rendering/template_name.rb,
lib/lotus/mailer/rendering/templates_finder.rb
Overview
Lotus::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 =
'0.1.0'.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(m) ⇒ Object (protected)
276 277 278 |
# File 'lib/lotus/mailer.rb', line 276 def method_missing(m) @locals.fetch(m) { super } end |
Class Method Details
.configure(&blk) ⇒ Object
Configure the framework. It yields the given block in the context of the configuration
60 61 62 63 |
# File 'lib/lotus/mailer.rb', line 60 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
113 114 115 |
# File 'lib/lotus/mailer.rb', line 113 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 Lotus::Mailer modules to the given Class. It sets a copy of the framework configuration
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/lotus/mailer.rb', line 75 def self.included(base) conf = self.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
121 122 123 124 |
# File 'lib/lotus/mailer.rb', line 121 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.
232 233 234 235 236 |
# File 'lib/lotus/mailer.rb', line 232 def deliver mail.deliver rescue ArgumentError raise MissingDeliveryDataError end |
#initialize(locals = {}) ⇒ Object
Initialize a mailer
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/lotus/mailer.rb', line 197 def initialize(locals = {}) @locals = locals @format = locals.fetch(:format, nil) @charset = charset = locals.fetch(:charset, self.class.configuration.default_charset) @mail = Mail.new.tap do |m| m.from = __dsl(:from) m.to = __dsl(:to) m.subject = __dsl(:subject) m.charset = charset m.html_part = __part(:html) m.text_part = __part(:txt) m.delivery_method(*Lotus::Mailer.configuration.delivery_method) end 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.
224 225 226 |
# File 'lib/lotus/mailer.rb', line 224 def render(format) self.class.templates(format).render(self, @locals) end |