Module: Hanami::Mailer::Dsl
- Defined in:
- lib/hanami/mailer/dsl.rb
Overview
Class level DSL
Class Method Summary collapse
- .extended(base) ⇒ Object private
Instance Method Summary collapse
-
#bcc(value = nil) ⇒ Object
Sets the bcc (blind carbon copy) for mail messages.
-
#cc(value = nil) ⇒ Object
Sets the cc (carbon copy) for mail messages.
-
#from(value = nil) ⇒ Object
Sets the sender for mail messages.
-
#subject(value = nil) ⇒ Object
Sets the subject for mail messages.
-
#template(value = nil) ⇒ Object
Set the template name IF it differs from the convention.
-
#templates(format = nil) ⇒ Object
private
Returns a set of associated templates or only one for the given format.
-
#to(value = nil) ⇒ Object
Sets the recipient for mail messages.
Class Method Details
.extended(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.
12 13 14 15 16 17 18 19 20 |
# File 'lib/hanami/mailer/dsl.rb', line 12 def self.extended(base) base.class_eval do @from = nil @to = nil @cc = nil @bcc = nil @subject = nil end end |
Instance Method Details
#bcc(value) ⇒ NilClass #bcc ⇒ String, ...
Sets the bcc (blind carbon copy) for mail messages
It accepts a hardcoded value as a string or array of strings. For dynamic values, you can specify a symbol that represents an instance method.
This value is optional.
When a value is given, it specifies the bcc for the email. When a value is not given, it returns the bcc of the email.
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
314 315 316 317 318 319 320 |
# File 'lib/hanami/mailer/dsl.rb', line 314 def bcc(value = nil) if value.nil? @bcc else @bcc = value end end |
#cc(value) ⇒ NilClass #cc ⇒ String, ...
Sets the cc (carbon copy) for mail messages
It accepts a hardcoded value as a string or array of strings. For dynamic values, you can specify a symbol that represents an instance method.
This value is optional.
When a value is given, it specifies the cc for the email. When a value is not given, it returns the cc of the email.
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
225 226 227 228 229 230 231 |
# File 'lib/hanami/mailer/dsl.rb', line 225 def cc(value = nil) if value.nil? @cc else @cc = value end end |
#from(value) ⇒ NilClass #from ⇒ String, Symbol
Sets the sender for mail messages
It accepts a hardcoded value as a string, or a symbol that represents an instance method for more complex logic.
This value MUST be set, otherwise an exception is raised at the delivery time.
When a value is given, specify the sender of the email Otherwise, it returns the sender of the email
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
136 137 138 139 140 141 142 |
# File 'lib/hanami/mailer/dsl.rb', line 136 def from(value = nil) if value.nil? @from else @from = value end end |
#subject(value) ⇒ NilClass #subject ⇒ String, Symbol
Sets the subject for mail messages
It accepts a hardcoded value as a string, or a symbol that represents an instance method for more complex logic.
This value MUST be set, otherwise an exception is raised at the delivery time.
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
456 457 458 459 460 461 462 |
# File 'lib/hanami/mailer/dsl.rb', line 456 def subject(value = nil) if value.nil? @subject else @subject = value end end |
#template(value) ⇒ NilClass #template ⇒ String
Set the template name IF it differs from the convention.
For a given mailer named Signup::Welcome
it will look for signup/welcome..
templates under the root directory.
If for some reason, we need to specify a different template name, we can use this method.
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
54 55 56 57 58 59 60 |
# File 'lib/hanami/mailer/dsl.rb', line 54 def template(value = nil) if value.nil? @template ||= ::Hanami::Mailer::Rendering::TemplateName.new(name, configuration.namespace).to_s else @template = value end end |
#templates(format) ⇒ Hash #templates ⇒ Hash
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.
Returns a set of associated templates or only one for the given format
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
80 81 82 83 84 85 86 |
# File 'lib/hanami/mailer/dsl.rb', line 80 def templates(format = nil) if format.nil? @templates = ::Hanami::Mailer::Rendering::TemplatesFinder.new(self).find else @templates.fetch(format, nil) end end |
#to(value) ⇒ NilClass #to ⇒ String, ...
Sets the recipient for mail messages
It accepts a hardcoded value as a string or array of strings. For dynamic values, you can specify a symbol that represents an instance method.
This value MUST be set, otherwise an exception is raised at the delivery time.
When a value is given, specify the recipient of the email Otherwise, it returns the recipient of the email
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding class variable. When called without, it will return the already set value, or the default.
400 401 402 403 404 405 406 |
# File 'lib/hanami/mailer/dsl.rb', line 400 def to(value = nil) if value.nil? @to else @to = value end end |