Class: SinatraHelpers::Mailer::Base
- Inherits:
-
Object
- Object
- SinatraHelpers::Mailer::Base
- Defined in:
- lib/sinatra_helpers/mailer/base.rb
Constant Summary collapse
- CONFIGS =
[:server, :domain, :port, :reply_to, :username, :password, :authentication, :content_type, :charset]
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(configs = {}) ⇒ Base
constructor
A new instance of Base.
- #send(settings = {}) ⇒ Object
Constructor Details
#initialize(configs = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sinatra_helpers/mailer/base.rb', line 17 def initialize(configs={}) CONFIGS.each do |config| instance_variable_set("@#{config}", configs[config]) end @authentication ||= :login @reply_to ||= @username @content_type ||= 'text/plain' @charset ||= 'UTF-8' @logger = block_given? ? yield : nil end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/sinatra_helpers/mailer/base.rb', line 15 def logger @logger end |
Instance Method Details
#send(settings = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sinatra_helpers/mailer/base.rb', line 28 def send(settings={}) check_configs [:to, :subject].each do |setting| raise SinatraHelpers::Mailer::SendError, "cannot send, #{setting} not specified." unless settings[setting] end mail = generate_mail(settings) mail.body = yield(mail) if block_given? mail.body ||= '' Sinatra::Application.environment.to_s == 'production' ? send_mail(mail) : log_mail(mail) log(:info, "Sent '#{mail.subject}' to #{mail.to.join(',')}") mail end |