Class: Backup::Mail::Base
- Inherits:
-
Object
- Object
- Backup::Mail::Base
- Defined in:
- lib/backup/mail/base.rb
Class Method Summary collapse
- .gsub_content(lines) ⇒ Object
-
.notify!(backup) ⇒ Object
Delivers the backup details by email to the recipient Requires the Backup Object.
- .parse_body ⇒ Object
-
.setup(config) ⇒ Object
Sets up the Mail Configuration for the Backup::Mail::Base class.
-
.setup? ⇒ Boolean
Returns true if the “to” and “from” attributes are set.
-
.smtp_configuration ⇒ Object
Retrieves SMTP configuration.
Class Method Details
.gsub_content(lines) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/backup/mail/base.rb', line 70 def self.gsub_content(lines) bucket = @backup.procedure.get_storage_configuration.attributes['bucket'] path = @backup.procedure.get_storage_configuration.attributes['path'] ip = @backup.procedure.get_storage_configuration.attributes['ip'] lines.each do |line| line.gsub!(':trigger', @backup.trigger) line.gsub!(':day', Time.now.strftime("%A (%d)")) line.gsub!(':month', Time.now.strftime("%B")) line.gsub!(':year', Time.now.strftime("%Y")) line.gsub!(':time', Time.now.strftime("%r")) line.gsub!(':adapter', @backup.procedure.adapter_name.to_s) line.gsub!(':location', bucket || path) line.gsub!(':backup', @backup.final_file) case @backup.procedure.storage_name.to_sym when :s3 then line.gsub!(':remote', "on Amazon S3") when :local then line.gsub!(':remote', "on the local server") when :scp, :sftp, :ftp then line.gsub!(':remote', "on the remote server (#{ip})") end @content ||= String.new @content << line end end |
.notify!(backup) ⇒ Object
Delivers the backup details by email to the recipient Requires the Backup Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/backup/mail/base.rb', line 35 def self.notify!(backup) if self.setup? and backup.procedure.attributes['notify'].eql?(true) @backup = backup self.parse_body PersonMailer.deliver_backup_notification(@backup.trigger, @content, :stream => :support) # Pony.mail({ # :subject => "Backup for \"#{@backup.trigger}\" was successfully created!", # :body => @content # }.merge(self.smtp_configuration)) puts "Sending notification to #{self.to}." end end |
.parse_body ⇒ Object
64 65 66 67 68 |
# File 'lib/backup/mail/base.rb', line 64 def self.parse_body File.open(File.join(File.dirname(__FILE__), 'mail.txt'), 'r') do |file| self.gsub_content(file.readlines) end end |
.setup(config) ⇒ Object
Sets up the Mail Configuration for the Backup::Mail::Base class. This must be set in order to send emails It will dynamically add class methods (configuration) for each email that will be sent
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/backup/mail/base.rb', line 10 def self.setup(config) if config (class << self; self; end).instance_eval do config.attributes.each do |method, value| define_method method do value end end config.get_smtp_configuration.attributes.each do |method, value| define_method method do value end end end end end |
.setup? ⇒ Boolean
Returns true if the “to” and “from” attributes are set
28 29 30 31 |
# File 'lib/backup/mail/base.rb', line 28 def self.setup? return true if defined?(from) and defined?(to) false end |
.smtp_configuration ⇒ Object
Retrieves SMTP configuration
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/backup/mail/base.rb', line 49 def self.smtp_configuration { :to => self.to, :from => self.from, :via => :smtp, :smtp => { :host => self.host, :port => self.port, :user => self.username, :password => self.password, :auth => self.authentication, :domain => self.domain, :tls => self.tls }} end |