Module: Roda::RodaPlugins::Mailer::ClassMethods

Defined in:
lib/roda/plugins/mailer.rb

Instance Method Summary collapse

Instance Method Details

#mail(path, *args) ⇒ Object

Return a Mail::Message instance for the email for the given request path and arguments. You can further manipulate the returned mail object before calling deliver to send the mail.



139
140
141
142
143
144
145
146
147
# File 'lib/roda/plugins/mailer.rb', line 139

def mail(path, *args)
  mail = ::Mail.new
  catch(:no_mail) do
    unless mail.equal?(new(PATH_INFO=>path, SCRIPT_NAME=>EMPTY_STRING, REQUEST_METHOD=>MAIL, RACK_INPUT=>StringIO.new, RODA_MAIL=>mail, RODA_MAIL_ARGS=>args).call(&route_block))
      raise Error, "route did not return mail instance for #{path.inspect}, #{args.inspect}"
    end
    mail
  end
end

#sendmail(*args) ⇒ Object

Calls mail and immediately sends the resulting mail.



150
151
152
153
154
# File 'lib/roda/plugins/mailer.rb', line 150

def sendmail(*args)
  if m = mail(*args)
    m.deliver
  end
end