Class: BarkestCore::EmailConfig
- Inherits:
-
Object
- Object
- BarkestCore::EmailConfig
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- app/models/barkest_core/email_config.rb
Overview
Defines the email configuration for the system.
Constant Summary collapse
- VALID_CONFIG_MODES =
%w(none smtp test)
- VALID_AUTH_MODES =
%w(none plain login cram_md5 ntlm)
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#config_mode ⇒ Object
Returns the value of attribute config_mode.
-
#default_hostname ⇒ Object
Returns the value of attribute default_hostname.
-
#default_recipient ⇒ Object
Returns the value of attribute default_recipient.
-
#default_sender ⇒ Object
Returns the value of attribute default_sender.
-
#enable_starttls_auto ⇒ Object
Returns the value of attribute enable_starttls_auto.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Class Method Summary collapse
-
.load ⇒ Object
Loads the configuration from SystemConfig.
Instance Method Summary collapse
-
#enable_starttls_auto? ⇒ Boolean
Is STARTTLS enabled for SMTP?.
-
#initialize(*args) ⇒ EmailConfig
constructor
Initializes the configuration.
-
#save ⇒ Object
Saves this configuration (encrypted) to SystemConfig.
-
#smtp? ⇒ Boolean
Is SMTP enabled?.
-
#ssl? ⇒ Boolean
Is SSL enabled for SMTP?.
-
#to_h ⇒ Object
Converts this configuration into a hash.
Constructor Details
#initialize(*args) ⇒ EmailConfig
Initializes the configuration.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/barkest_core/email_config.rb', line 29 def initialize(*args) args.each do |arg| if arg.is_a?(Hash) arg.each do |k,v| if respond_to?(:"#{k}?") send :"#{k}=", ((v === true || v === '1') ? '1' : '0') elsif respond_to?(k) send :"#{k}=", v.to_s end end end end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def address @address end |
#authentication ⇒ Object
Returns the value of attribute authentication.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def authentication @authentication end |
#config_mode ⇒ Object
Returns the value of attribute config_mode.
8 9 10 |
# File 'app/models/barkest_core/email_config.rb', line 8 def config_mode @config_mode end |
#default_hostname ⇒ Object
Returns the value of attribute default_hostname.
8 9 10 |
# File 'app/models/barkest_core/email_config.rb', line 8 def default_hostname @default_hostname end |
#default_recipient ⇒ Object
Returns the value of attribute default_recipient.
8 9 10 |
# File 'app/models/barkest_core/email_config.rb', line 8 def default_recipient @default_recipient end |
#default_sender ⇒ Object
Returns the value of attribute default_sender.
8 9 10 |
# File 'app/models/barkest_core/email_config.rb', line 8 def default_sender @default_sender end |
#enable_starttls_auto ⇒ Object
Returns the value of attribute enable_starttls_auto.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def enable_starttls_auto @enable_starttls_auto end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def port @port end |
#ssl ⇒ Object
Returns the value of attribute ssl.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def ssl @ssl end |
#user_name ⇒ Object
Returns the value of attribute user_name.
9 10 11 |
# File 'app/models/barkest_core/email_config.rb', line 9 def user_name @user_name end |
Class Method Details
.load ⇒ Object
Loads the configuration from SystemConfig.
87 88 89 |
# File 'app/models/barkest_core/email_config.rb', line 87 def EmailConfig.load EmailConfig.new SystemConfig.get(:email) end |
Instance Method Details
#enable_starttls_auto? ⇒ Boolean
Is STARTTLS enabled for SMTP?
57 58 59 |
# File 'app/models/barkest_core/email_config.rb', line 57 def enable_starttls_auto? enable_starttls_auto.to_s.to_i != 0 end |
#save ⇒ Object
Saves this configuration (encrypted) to SystemConfig.
81 82 83 |
# File 'app/models/barkest_core/email_config.rb', line 81 def save SystemConfig.set :email, to_h, true end |
#smtp? ⇒ Boolean
Is SMTP enabled?
45 46 47 |
# File 'app/models/barkest_core/email_config.rb', line 45 def smtp? config_mode.to_s.downcase == 'smtp' end |
#ssl? ⇒ Boolean
Is SSL enabled for SMTP?
51 52 53 |
# File 'app/models/barkest_core/email_config.rb', line 51 def ssl? ssl.to_s.to_i != 0 end |
#to_h ⇒ Object
Converts this configuration into a hash.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/barkest_core/email_config.rb', line 63 def to_h { config_mode: config_mode.to_s.to_sym, default_sender: default_sender.to_s, default_recipient: default_recipient.to_s, default_hostname: default_hostname.to_s, address: address.to_s, port: port.to_s.to_i, authentication: authentication.to_s.to_sym, ssl: ssl?, enable_starttls_auto: enable_starttls_auto?, user_name: user_name.to_s, password: password.to_s, } end |