Module: Aerogel::Mailer
- Defined in:
- lib/aerogel/mailer/core.rb,
lib/aerogel/mailer/error.rb,
lib/aerogel/mailer/version.rb,
lib/aerogel/mailer/definition.rb
Defined Under Namespace
Classes: Definition, Error
Constant Summary collapse
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.registered(app) ⇒ Object
Configures module Aerogel::Mailer.
Instance Method Summary collapse
-
#email(name, *args) ⇒ Object
Deliver email using mailer specified by
name
. -
#email_with_context(context, name, *args) ⇒ Object
Deliver email using mailer specified by
name
. -
#mailer(name, &block) ⇒ Object
Registers new mailer.
Class Method Details
.registered(app) ⇒ Object
Configures module Aerogel::Mailer
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aerogel/mailer/core.rb', line 7 def self.registered(app) aerogel_delivery_method = Aerogel.config.mailer.delivery_method = Aerogel.config.mailer..raw || {} Mail.defaults do delivery_method aerogel_delivery_method, end # load mailers Aerogel::get_resource_list( :app, "mailers/**/*.rb" ).each do |filename| Aerogel.require_into( Aerogel::Application, filename ) end # register reloader setup_reloader(app) if Aerogel.config.aerogel.reloader? end |
Instance Method Details
#email(name, *args) ⇒ Object
Deliver email using mailer specified by name
32 33 34 |
# File 'lib/aerogel/mailer/core.rb', line 32 def email( name, *args ) email_with_context( self, name, *args ) end |
#email_with_context(context, name, *args) ⇒ Object
Deliver email using mailer specified by name
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/aerogel/mailer/core.rb', line 38 def email_with_context( context, name, *args ) mailer = Aerogel::Mailer::Definition.mailers[name.to_sym] unless mailer raise ArgumentError.new "Mailer '#{name}' is not defined" end params = mailer.compile( context, *args ) puts "** sending mail: #{params}" begin = Mail.new do from params[:from] to params[:to] subject params[:subject] text_part do content_type 'text/plain; charset=UTF-8' body params[:body][:text] end if params[:body][:text] html_part do content_type 'text/html; charset=UTF-8' body params[:body][:html] end if params[:body][:html] end .charset = "UTF-8" .deliver rescue StandardError => e raise Aerogel::Mailer::Error.new "Mailer '#{name}' failed to deliver email: #{e}" end true end |
#mailer(name, &block) ⇒ Object
Registers new mailer
26 27 28 |
# File 'lib/aerogel/mailer/core.rb', line 26 def mailer( name, &block ) Definition.new name, block end |