Class: Hanami::Mailer::Configuration
- Inherits:
-
Object
- Object
- Hanami::Mailer::Configuration
- Defined in:
- lib/hanami/mailer/configuration.rb
Overview
Framework configuration
Constant Summary collapse
- DEFAULT_ROOT =
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.
Default root
"."
- DEFAULT_DELIVERY_METHOD =
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.
Default delivery method
:smtp
- DEFAULT_CHARSET =
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.
Default charset
"UTF-8"
Instance Attribute Summary collapse
- #default_charset(value = nil) ⇒ Object readonly
-
#delivery_method(method = nil, options = {}) ⇒ Array
readonly
Specify a global delivery method for the mail gateway.
- #mailers ⇒ Object readonly private
- #modules ⇒ Object readonly private
-
#namespace(value = nil) ⇒ Object
readonly
private
Set the Ruby namespace where to lookup for mailers.
-
#root(value = nil) ⇒ Object
readonly
Set the root path where to search for templates.
Instance Method Summary collapse
-
#add_mailer(mailer) ⇒ Object
private
Add a mailer to the registry.
-
#copy!(base) ⇒ Object
private
Copy the configuration for the given mailer.
-
#duplicate ⇒ Hanami::Mailer::Configuration
private
Duplicate by copying the settings in a new instance.
-
#initialize ⇒ Hanami::Mailer::Configuration
constructor
Initialize a configuration instance.
-
#load! ⇒ Object
Load the configuration.
-
#prepare(&blk) ⇒ void
Prepare the mailers.
-
#reset! ⇒ Object
(also: #unload!)
Reset the configuration.
Constructor Details
#initialize ⇒ Hanami::Mailer::Configuration
Initialize a configuration instance
43 44 45 46 |
# File 'lib/hanami/mailer/configuration.rb', line 43 def initialize @namespace = Object reset! end |
Instance Attribute Details
#default_charset(value = nil) ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/hanami/mailer/configuration.rb', line 279 def default_charset(value = nil) if value.nil? @default_charset else @default_charset = value end end |
#delivery_method(method = nil, options = {}) ⇒ Array
Specify a global delivery method for the mail gateway.
It supports the following delivery methods:
* Exim (<tt>:exim</tt>)
* Sendmail (<tt>:sendmail</tt>)
* SMTP (<tt>:smtp</tt>, for local installations)
* SMTP Connection (<tt>:smtp_connection</tt>,
via <tt>Net::SMTP</tt> - for remote installations)
* Test (<tt>:test</tt>, for testing purposes)
The default delivery method is SMTP (:smtp
).
Custom delivery methods can be specified by passing the class policy and a set of optional configurations. This class MUST respond to:
* <tt>initialize(options = {})</tt>
* <tt>deliver!(mail)<tt>
270 271 272 273 274 275 276 |
# File 'lib/hanami/mailer/configuration.rb', line 270 def delivery_method(method = nil, = {}) if method.nil? @delivery_method else @delivery_method = [method, ] end end |
#mailers ⇒ Object (readonly)
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.
32 33 34 |
# File 'lib/hanami/mailer/configuration.rb', line 32 def mailers @mailers end |
#modules ⇒ 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.
36 37 38 |
# File 'lib/hanami/mailer/configuration.rb', line 36 def modules @modules end |
#namespace(value) ⇒ Object #namespace ⇒ Class, ...
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.
Set the Ruby namespace where to lookup for mailers.
When multiple instances of the framework are used, we want to make sure that if a ‘MyApp` wants a `Mailers::Signup` mailer, we are loading the right one.
If not set, this value defaults to ‘Object`.
This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding instance variable. When called without, it will return the already set value, or the default.
82 83 84 85 86 87 88 |
# File 'lib/hanami/mailer/configuration.rb', line 82 def namespace(value = nil) if value @namespace = value else @namespace end end |
#root(value) ⇒ Object #root ⇒ Pathname
Set the root path where to search for templates
If not set, this value defaults to the current directory.
When this method is called with an argument, it will set the corresponding instance variable. When called without, it will return the already set value, or the default.
124 125 126 127 128 129 130 |
# File 'lib/hanami/mailer/configuration.rb', line 124 def root(value = nil) if value @root = Utils::Kernel.Pathname(value).realpath else @root end end |
Instance Method Details
#add_mailer(mailer) ⇒ 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.
Add a mailer to the registry
160 161 162 |
# File 'lib/hanami/mailer/configuration.rb', line 160 def add_mailer(mailer) @mailers.add(mailer) end |
#copy!(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.
Copy the configuration for the given mailer
206 207 208 209 210 |
# File 'lib/hanami/mailer/configuration.rb', line 206 def copy!(base) modules.each do |mod| base.class_eval(&mod) end end |
#duplicate ⇒ Hanami::Mailer::Configuration
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.
Duplicate by copying the settings in a new instance.
170 171 172 173 174 175 176 177 178 |
# File 'lib/hanami/mailer/configuration.rb', line 170 def duplicate Configuration.new.tap do |c| c.namespace = namespace c.root = root.dup c.modules = modules.dup c.delivery_method = delivery_method c.default_charset = default_charset end end |
#load! ⇒ Object
Load the configuration
181 182 183 184 |
# File 'lib/hanami/mailer/configuration.rb', line 181 def load! mailers.each { |m| m.__send__(:load!) } freeze end |
#prepare(&blk) ⇒ void
This method returns an undefined value.
Prepare the mailers.
The given block will be yielded when ‘Hanami::Mailer` will be included by a mailer.
This method can be called multiple times.
148 149 150 151 152 153 154 |
# File 'lib/hanami/mailer/configuration.rb', line 148 def prepare(&blk) if block_given? @modules.push(blk) else raise ArgumentError.new("Please provide a block") end end |
#reset! ⇒ Object Also known as: unload!
Reset the configuration
187 188 189 190 191 192 193 194 |
# File 'lib/hanami/mailer/configuration.rb', line 187 def reset! root(DEFAULT_ROOT) delivery_method(DEFAULT_DELIVERY_METHOD) default_charset(DEFAULT_CHARSET) @mailers = Set.new @modules = [] end |