rake_mailer 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 299455552d3cd47022a723dfc93534416534c214
4
- data.tar.gz: 35e158ddc1d76257df5a35d8ee473812b5c2c982
3
+ metadata.gz: e183447300947e6b627c4b125632ab458dd63a88
4
+ data.tar.gz: a6fbc5da91c0e4e003a2e8ea39aa30777274ebf6
5
5
  SHA512:
6
- metadata.gz: 64d8c86f7b0393d35777b3c3d91123bed33a3a9684685473cba8da69855db3315323dd9fde0090be967c3e188249bf3904b4e50086b10e17351a746a19dc9a98
7
- data.tar.gz: b79ca44bd5954d8b8b3240ee5008e04075430991bed3d70257686016d8be7bad13ead70d5e0bde6d0f265d4d2cb930c6dbf9598163077e19646e0c79ae012a1b
6
+ metadata.gz: 5d7c29ee030a66b4ce10b40d47693c8ec40500881efaebde661af6fd8f199b72d4e4ff8fdbf66febde2a60dfedcfae1aae437514ba4b870e0b145cc3c00f1ead
7
+ data.tar.gz: 3eea4ec1f4a6b01a6677f3c01a1d68f1ccdffb003dc79e9bd8294970d4d5c5ce05870dd1aeec357a260a822ee9d9f7752443c04f0636b208f08ceb561f0b0758
data/README.md CHANGED
@@ -23,6 +23,16 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install rake_mailer
25
25
 
26
+ ### Configuration Details:
27
+ 'from'- It is compulsory. It must be a string.
28
+ 'emails'- It is compulsory if a email has to be sent somewhere.
29
+ It can we a string or an array of strings
30
+ 'file_path'- system path where the rake mailer can store its generated reports.
31
+ By default it uses tmp/rake_mailer in the app's root directory
32
+ 'display_system_info'- By default it is set to true. If true it will send some
33
+ system information in the body of the email.
34
+
35
+
26
36
  ## Usage
27
37
 
28
38
  ### Create a rake_mailer.yml in config
@@ -30,6 +40,7 @@ Or install it yourself as:
30
40
  from: 'gemin.patel61@gmail.com'
31
41
  emails: ['arjun.verma@gmail.com', 'kamal.soni@gmail.com']
32
42
  file_path: 'tmp/rake_mailer'
43
+ display_system_info: true
33
44
 
34
45
  ### Sample Rake Task will now look like
35
46
  namespace :bug_fixes do
data/lib/rake_mailer.rb CHANGED
@@ -7,36 +7,77 @@ require 'fileutils'
7
7
  module RakeMailer
8
8
  class FileWriter
9
9
  def initialize(emails = nil)
10
+ load_yml
11
+ set_email_config(emails)
12
+ set_file_config
13
+ create_file_path
14
+ open_file
15
+ end
16
+
17
+ def file_writer(line)
18
+ begin
19
+ @file.write(line)
20
+ @file.write("\n")
21
+ rescue Exception => e
22
+ puts "ERROR: Block in file_writer. Rescued. Could not write in the file => #{e.message}"
23
+ end
24
+ end
25
+
26
+ def close
27
+ begin
28
+ @file.close
29
+ rescue Exception => e
30
+ puts "ERROR: Block in close. Rescued. Will attempt to send the mail. Could close the file => #{e.message}"
31
+ end
32
+ send_email
33
+ end
34
+
35
+ private
36
+ def load_yml
10
37
  yml_file = YAML.load_file("#{Rails.root}/config/rake_mailer.yml")
11
38
  if yml_file && yml_file[Rails.env]
12
39
  @rake_mailer_constants = yml_file[Rails.env]
13
- @from = @rake_mailer_constants['from']
14
- @emails = emails || @rake_mailer_constants['emails']
15
- @subject = "[Rake Mailer] Report for #{Rake.application.top_level_tasks.first}"
16
- config_file_path = @rake_mailer_constants['file_path']
17
- @filename = Time.now.to_i.to_s + "_#{Rake.application.top_level_tasks.first}" + '.txt'
18
- FileUtils::mkdir_p(config_file_path || 'tmp/rake_mailer')
19
- @file_location = File.join(Rails.root, (config_file_path || 'tmp/rake_mailer'), @filename)
20
- @file = open(@file_location, 'w')
21
40
  else
22
41
  raise 'ERROR: gem rake_mailer => configuration file is incorrect'
23
42
  end
24
43
  end
25
44
 
26
- def file_writer(line)
27
- @file.write(line)
28
- @file.write("\n")
45
+ def set_email_config(emails)
46
+ @emails = emails || @rake_mailer_constants['emails']
47
+ @from = @rake_mailer_constants['from']
48
+ @subject = "[Rake Mailer] Report for #{Rake.application.top_level_tasks.first}"
49
+ set_display_system_info_config
29
50
  end
30
51
 
31
- def close
32
- @file.close
33
- send_email
52
+ def set_display_system_info_config
53
+ @display_system_info = @rake_mailer_constants['display_system_info'].nil? ? true : @rake_mailer_constants['display_system_info']
54
+ end
55
+
56
+ def set_file_config
57
+ @filename = Time.now.to_i.to_s + "_#{Rake.application.top_level_tasks.first}" + '.txt'
58
+ @file_path = @rake_mailer_constants['file_path'] || 'tmp/rake_mailer'
59
+ @file_location = File.join(Rails.root, (@file_path), @filename)
60
+ end
61
+
62
+ def create_file_path
63
+ begin
64
+ FileUtils::mkdir_p(@file_path)
65
+ rescue Exception => e
66
+ raise "ERROR: Block in create_file_path. Could not create folder => #{e.message}"
67
+ end
68
+ end
69
+
70
+ def open_file
71
+ begin
72
+ @file = open(@file_location, 'w')
73
+ rescue Exception => e
74
+ raise "ERROR: Block in open_file. Could not open the file => #{e.message}"
75
+ end
34
76
  end
35
77
 
36
- private
37
78
  def send_email
38
79
  if @from.present? && @emails.present? && (@from.is_a? String) && ((@emails.is_a? String) || (@emails.is_a? Array))
39
- RakeMailer::MailIt.custom_text_email(@from, @emails, @file_location, @filename, @subject).deliver_now
80
+ RakeMailer::MailIt.custom_text_email(@from, @emails, @file_location, @filename, @subject, @display_system_info).deliver_now
40
81
  end
41
82
  end
42
83
  end
@@ -1,31 +1,41 @@
1
1
  require 'socket'
2
2
  module RakeMailer
3
3
  class MailIt < ActionMailer::Base
4
- def custom_text_email(from, to, file_location, filename, subject)
4
+ def custom_text_email(from, to, file_location, filename, subject, display_system_info)
5
5
  attachments[filename] = File.read(file_location)
6
+ body = display_system_info ? (body_text rescue "System Info Unsuccessful\n\npfa") : 'pfa'
6
7
  mail :from => from,
7
8
  :to => to,
8
9
  :subject => subject do |format|
9
- format.text { render text: body_text }
10
+ format.text { render text: body }
10
11
  end
11
12
  end
13
+
12
14
  private
13
15
  def body_text
14
- s = ''
15
- s << "IP: #{Socket.ip_address_list.find {|a| !(a.ipv4_loopback?) }.ip_address}\n"
16
- s << "Host Name: #{Socket.gethostname}\n"
17
- s << "User: #{ENV['USERNAME']}\n"
18
- s << "Time: #{Time.now}\n"
16
+ s = "GENERAL INFO\n"
17
+ s << "\tIP: #{Socket.ip_address_list.find {|a| !(a.ipv4_loopback?) }.ip_address}\n"
18
+ s << "\tHost: #{Socket.gethostname}\n"
19
+ s << "\tUser: #{ENV['USERNAME']}\n\n"
20
+ s << "\nTIME INFO\n"
21
+ s << "\tTime: #{Time.now.asctime}\n\n"
22
+ db_config = Rails.configuration.database_configuration[Rails.env]
23
+ s << "\nDATABASE INFO\n"
24
+ s << "\tAdapter: #{db_config['adapter']}\n"
25
+ s << "\tDatabase: #{db_config['database']}\n"
26
+ s << "\tHost: #{db_config['host']}\n\n"
19
27
  begin
28
+ s << "\nSYSTEM INFO\n"
20
29
  output = %x(free)
21
- s << "Total Memory: #{output.split(" ")[7]}\n"
22
- s << "Used Memory: #{output.split(" ")[8]}\n"
23
- s << "Free Memory: #{output.split(" ")[9]}\n"
30
+ s << "\tTotal Memory: #{output.split(" ")[7]} KB\n"
31
+ s << "\tUsed Memory: #{output.split(" ")[8]} KB\n"
32
+ s << "\tFree Memory: #{output.split(" ")[9]} KB\n"
24
33
  rescue
34
+ puts "ERROR: Block in body_text. Could not run command 'free' => #{e.message}"
25
35
  end
26
36
  s << "\npfa\n"
27
37
  s << "\n\nregards,\n"
28
- s << "Rake Mailer,\n"
38
+ s << "Rake Mailer\n"
29
39
  s
30
40
  end
31
41
  end
@@ -1,3 +1,3 @@
1
1
  module RakeMailer
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gemin Patel