Class: BarkestCore::EmailConfig

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#addressObject

Returns the value of attribute address.



9
10
11
# File 'app/models/barkest_core/email_config.rb', line 9

def address
  @address
end

#authenticationObject

Returns the value of attribute authentication.



9
10
11
# File 'app/models/barkest_core/email_config.rb', line 9

def authentication
  @authentication
end

#config_modeObject

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_hostnameObject

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_recipientObject

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_senderObject

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_autoObject

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

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'app/models/barkest_core/email_config.rb', line 9

def password
  @password
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'app/models/barkest_core/email_config.rb', line 9

def port
  @port
end

#sslObject

Returns the value of attribute ssl.



9
10
11
# File 'app/models/barkest_core/email_config.rb', line 9

def ssl
  @ssl
end

#user_nameObject

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

.loadObject

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?

Returns:

  • (Boolean)


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

#saveObject

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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


51
52
53
# File 'app/models/barkest_core/email_config.rb', line 51

def ssl?
  ssl.to_s.to_i != 0
end

#to_hObject

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