Class: Mailer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mailer/config.rb

Constant Summary collapse

CONFIGS =

TODO: look into abstracting port settings better based on server access type

> ie, TLS or SSL or whatever

[:smtp_helo_domain, :smtp_server, :smtp_port, :smtp_username, :smtp_password, :smtp_auth_type, :environment, :default_from]
NOT_REQUIRED =
[:default_from]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
19
20
21
# File 'lib/mailer/config.rb', line 15

def initialize()
  @logger = Log4r::Logger.new("[mailer]")
  @logger.add(Log4r::StdoutOutputter.new('console'))

  @smtp_auth_type ||= :login
  @environment ||= Mailer::ENVIRONMENT[:development]
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/mailer/config.rb', line 13

def logger
  @logger
end

Instance Method Details

#checkObject



41
42
43
44
45
# File 'lib/mailer/config.rb', line 41

def check
  CONFIGS.reject{|c| NOT_REQUIRED.include?(c)}.each do |config|
    raise Mailer::ConfigError, "#{config} not configured." unless instance_variable_get("@#{config}")
  end
end

#development?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/mailer/config.rb', line 47

def development?
  environment.to_s == Mailer::ENVIRONMENT[:development]
end

#log_file=(file) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/mailer/config.rb', line 30

def log_file=(file)
  begin
    @logger.add(Log4r::FileOutputter.new('fileOutputter', {
      :filename => file,
      :trunc => false,
      :formatter => Log4r::PatternFormatter.new(:pattern => "[%l] %d :: %m")
    }))
  rescue Exception => err
  end
end

#production?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/mailer/config.rb', line 53

def production?
  environment.to_s == Mailer::ENVIRONMENT[:production]
end

#smtp_username=(value) ⇒ Object



23
24
25
26
27
28
# File 'lib/mailer/config.rb', line 23

def smtp_username=(value)
  if @default_from.nil? && value && !value.match(/\A([\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i).nil?
    @default_from = value
  end
  @smtp_username = value
end

#test?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/mailer/config.rb', line 50

def test?
  environment.to_s == Mailer::ENVIRONMENT[:test]
end