rubycron 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Gemfile +6 -1
  2. data/lib/rubycron.rb +16 -12
  3. metadata +10 -5
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
1
  source :rubygems
2
2
 
3
- gem "mail"
3
+ gem "mail"
4
+
5
+ group :test do
6
+ gem "rspec", "~> 2.0"
7
+ gem "simplecov"
8
+ end
data/lib/rubycron.rb CHANGED
@@ -13,14 +13,14 @@ module RubyCron
13
13
  require 'erb'
14
14
 
15
15
  attr_accessor :name, :author, :mailto, :mailfrom, :mailsubject, :mailon, :exiton, :template, :smtpsettings, :logfile, :verbose
16
- attr_reader :warnings, :errors
16
+ attr_reader :warnings, :errors, :report
17
17
 
18
18
  def initialize(args = nil)
19
19
  @warnings, @errors = [], []
20
20
 
21
21
  case args
22
22
  when NilClass then yield self if block_given?
23
- when Proc then instance_eval(args)
23
+ when Proc then instance_eval(&args)
24
24
  when Hash then
25
25
 
26
26
  args = load_config(:file, args[:configfile]).merge(args) if args[:configfile]
@@ -45,12 +45,14 @@ module RubyCron
45
45
  io = open(source)
46
46
  end
47
47
  yml = YAML::load(io)
48
- return yml if yml.is_a?(Hash)
49
- return {}
48
+ if yml.is_a?(Hash)
49
+ return yml
50
+ else
51
+ terminate "Could not load the YAML configuration."
52
+ end
50
53
  end
51
54
 
52
55
  def check_sanity
53
-
54
56
  raise "This job has no name." unless @name
55
57
  raise "This job has no author." unless @author
56
58
  raise "No To: header was set. " unless @mailto
@@ -58,7 +60,6 @@ module RubyCron
58
60
  check_smtp_settings
59
61
  set_defaults
60
62
  enable_file_logging if @logfile
61
-
62
63
  end
63
64
 
64
65
  def check_smtp_settings
@@ -66,7 +67,7 @@ module RubyCron
66
67
  raise "SMTP settings have to be passed in as a hash." unless @smtpsettings.instance_of?(Hash)
67
68
  raise "SMTP settings should include at least an address (:address)." unless @smtpsettings.keys.include?(:address)
68
69
  raise "SMTP settings should include at least a port number (:port)." unless @smtpsettings.keys.include?(:port)
69
- else
70
+ elsif @smtpsettings.nil?
70
71
  raise "Cannot connect to local smtp server." unless smtp_connection?
71
72
  end
72
73
  end
@@ -84,12 +85,12 @@ module RubyCron
84
85
  $stdout.sync = true
85
86
  $stderr.reopen($stdout)
86
87
  rescue => e
87
- $stdout = STDOUT
88
+ $stdout, $stderr = STDOUT, STDERR
88
89
  raise e
89
90
  end
90
91
 
91
92
  def terminate(message)
92
- $stderr.puts "## Cannot complete job. Reason: #{message}"
93
+ $stderr.puts "## Cannot complete job. Reason: #{message}" unless ENV['RSPEC']
93
94
  exit 1
94
95
  end
95
96
 
@@ -110,7 +111,7 @@ module RubyCron
110
111
  puts "Number of errors : #{@errors.size}"
111
112
  end
112
113
  unless self.mailon == :none || (@warnings.empty? && @errors.empty? && self.mailon != :all)
113
- report
114
+ send_report
114
115
  end
115
116
  end
116
117
 
@@ -128,6 +129,7 @@ module RubyCron
128
129
 
129
130
  private
130
131
  def smtp_connection?
132
+ #return true if ENV['RSPEC']
131
133
  return true if Net::SMTP.start('localhost', 25)
132
134
  rescue
133
135
  return false
@@ -136,12 +138,14 @@ module RubyCron
136
138
  # Report on the status of the cronjob through the use of
137
139
  # an erb template file, and mikel's excellent mail gem.
138
140
  private
139
- def report
141
+ def send_report
142
+ @report = ERB.new(File.read(@template)).result(binding)
140
143
  @mailsubject = "Cron report for #{name}: #{@warnings.size} warnings & #{@errors.size} errors" unless @mailsubject
144
+
141
145
  mailfrom = @mailfrom
142
146
  mailto = @mailto
143
147
  mailsubject = @mailsubject
144
- mailbody = ERB.new(File.read(@template)).result(binding)
148
+ mailbody = @report
145
149
 
146
150
  if @smtpsettings
147
151
  smtpsettings = @smtpsettings
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-14 00:00:00.000000000Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
16
- requirement: &2153963780 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153963780
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: Write clean cronjobs in Ruby, and get reporting for free!
26
31
  email: rubycron@kamphorst.com
27
32
  executables:
@@ -56,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
61
  version: '0'
57
62
  requirements: []
58
63
  rubyforge_project:
59
- rubygems_version: 1.8.15
64
+ rubygems_version: 1.8.24
60
65
  signing_key:
61
66
  specification_version: 3
62
67
  summary: Simplifies your Ruby cronjobs by automating the reporting process.