Class: RequestLogAnalyzer::Mailer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to, host = 'localhost', options = {}) ⇒ Mailer

Initialize a mailer to to address host the mailer host options Specific style options



11
12
13
14
15
16
17
# File 'lib/request_log_analyzer/mailer.rb', line 11

def initialize(to, host = 'localhost', options = {})
  require 'net/smtp' 
  @to      = to
  @host    = host
  @options = options
  @data    = []
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/request_log_analyzer/mailer.rb', line 5

def data
  @data
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/request_log_analyzer/mailer.rb', line 5

def host
  @host
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/request_log_analyzer/mailer.rb', line 5

def to
  @to
end

Instance Method Details

#<<(string) ⇒ Object



37
38
39
# File 'lib/request_log_analyzer/mailer.rb', line 37

def << string
  data << string
end

#mailObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/request_log_analyzer/mailer.rb', line 19

def mail
  from        = @options[:from]        || '[email protected]'
  from_alias  = @options[:from_alias]  || 'Request-log-analyzer reporter'
  to_alias    = @options[:to_alias]    || to
  subject     = @options[:subjeect]    || "Request log analyzer report - generated on #{Time.now.to_s}"
msg = <<END_OF_MESSAGE
From: #{from_alias} <#{from}>
To: #{to_alias} <#{@to}>
Subject: #{subject}

#{@data.to_s}
END_OF_MESSAGE
  
  Net::SMTP.start(@host) do |smtp|
    smtp.send_message msg, from, to
  end
end

#puts(string) ⇒ Object



41
42
43
# File 'lib/request_log_analyzer/mailer.rb', line 41

def puts string
  data << string
end