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
'.'.freeze
- 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'.freeze
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
41 42 43 44 |
# File 'lib/hanami/mailer/configuration.rb', line 41 def initialize @namespace = Object reset! end |
Instance Attribute Details
#default_charset(value = nil) ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/hanami/mailer/configuration.rb', line 277 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>
268 269 270 271 272 273 274 |
# File 'lib/hanami/mailer/configuration.rb', line 268 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.
30 31 32 |
# File 'lib/hanami/mailer/configuration.rb', line 30 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.
34 35 36 |
# File 'lib/hanami/mailer/configuration.rb', line 34 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.
80 81 82 83 84 85 86 |
# File 'lib/hanami/mailer/configuration.rb', line 80 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.
122 123 124 125 126 127 128 |
# File 'lib/hanami/mailer/configuration.rb', line 122 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
158 159 160 |
# File 'lib/hanami/mailer/configuration.rb', line 158 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
204 205 206 207 208 |
# File 'lib/hanami/mailer/configuration.rb', line 204 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.
168 169 170 171 172 173 174 175 176 |
# File 'lib/hanami/mailer/configuration.rb', line 168 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
179 180 181 182 |
# File 'lib/hanami/mailer/configuration.rb', line 179 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.
146 147 148 149 150 151 152 |
# File 'lib/hanami/mailer/configuration.rb', line 146 def prepare(&blk) if block_given? # rubocop:disable Style/GuardClause @modules.push(blk) else raise ArgumentError.new('Please provide a block') end end |
#reset! ⇒ Object Also known as: unload!
Reset the configuration
185 186 187 188 189 190 191 192 |
# File 'lib/hanami/mailer/configuration.rb', line 185 def reset! root(DEFAULT_ROOT) delivery_method(DEFAULT_DELIVERY_METHOD) default_charset(DEFAULT_CHARSET) @mailers = Set.new @modules = [] end |