javan-whenever 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.0 / June 2nd, 2009
2
+
3
+ * Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]
4
+
1
5
  == 0.2.2 / April 30th, 2009
2
6
 
3
7
  * Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]
data/Manifest CHANGED
@@ -10,6 +10,7 @@ lib/job_types/runner.rb
10
10
  lib/outputs/cron.rb
11
11
  lib/version.rb
12
12
  lib/whenever.rb
13
+ Manifest
13
14
  Rakefile
14
15
  README.rdoc
15
16
  test/command_line_test.rb
@@ -20,4 +21,3 @@ test/output_rake_test.rb
20
21
  test/output_runner_test.rb
21
22
  test/test_helper.rb
22
23
  whenever.gemspec
23
- Manifest
data/bin/whenever CHANGED
@@ -24,6 +24,9 @@ OptionParser.new do |opts|
24
24
  opts.on('-u', '--user [user]', 'Default: current user') do |user|
25
25
  options[:user] = user if user
26
26
  end
27
+ opts.on('-s', '--set [variables]', 'Example: --set environment=staging&path=/my/sweet/path') do |set|
28
+ options[:set] = set if set
29
+ end
27
30
  end.parse!
28
31
 
29
32
  Whenever::CommandLine.execute(options)
data/lib/command_line.rb CHANGED
@@ -28,7 +28,7 @@ module Whenever
28
28
  elsif @options[:write]
29
29
  write_crontab(whenever_cron)
30
30
  else
31
- puts Whenever.cron(:file => @options[:file])
31
+ puts Whenever.cron(@options)
32
32
  exit
33
33
  end
34
34
  end
@@ -40,7 +40,7 @@ module Whenever
40
40
  end
41
41
 
42
42
  def whenever_cron
43
- @whenever_cron ||= [comment_open, Whenever.cron(:file => @options[:file]), comment_close].join("\n")
43
+ @whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].join("\n")
44
44
  end
45
45
 
46
46
  def read_crontab
data/lib/job_list.rb CHANGED
@@ -5,20 +5,24 @@ module Whenever
5
5
  @jobs = Hash.new
6
6
  @env = Hash.new
7
7
 
8
- config = case options
9
- when String then options
8
+ case options
9
+ when String
10
+ config = options
10
11
  when Hash
11
- if options[:string]
12
+ config = if options[:string]
12
13
  options[:string]
13
14
  elsif options[:file]
14
15
  File.read(options[:file])
15
16
  end
17
+ pre_set(options[:set])
16
18
  end
17
19
 
18
20
  eval(config)
19
21
  end
20
22
 
21
23
  def set(variable, value)
24
+ return if instance_variable_defined?("@#{variable}".to_sym)
25
+
22
26
  instance_variable_set("@#{variable}".to_sym, value)
23
27
  self.class.send(:attr_reader, variable.to_sym)
24
28
  end
@@ -57,6 +61,20 @@ module Whenever
57
61
  end
58
62
 
59
63
  private
64
+
65
+ # Takes a string like: "variable1=something&variable2=somethingelse"
66
+ # and breaks it into variable/value pairs. Used for setting variables at runtime from the command line.
67
+ # Only works for setting values as strings.
68
+ def pre_set(variable_string = nil)
69
+ return if variable_string.blank?
70
+
71
+ pairs = variable_string.split('&')
72
+ pairs.each do |pair|
73
+ next unless pair.index('=')
74
+ variable, value = *pair.split('=')
75
+ set(variable.strip, value.strip) unless variable.blank? || value.blank?
76
+ end
77
+ end
60
78
 
61
79
  def environment_variables
62
80
  return if @env.empty?
data/lib/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Whenever
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 2
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -67,4 +67,21 @@ class OutputCommandTest < Test::Unit::TestCase
67
67
  end
68
68
  end
69
69
 
70
+ context "A command when the cron_log is set and is overridden by the :set option" do
71
+ setup do
72
+ @output = Whenever.cron :set => 'cron_log=otherlog.log', :string => \
73
+ <<-file
74
+ set :cron_log, 'logfile.log'
75
+ every 2.hours do
76
+ command "blahblah"
77
+ end
78
+ file
79
+ end
80
+
81
+ should "output the otherlog.log as the log file" do
82
+ assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
83
+ assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
84
+ end
85
+ end
86
+
70
87
  end
@@ -122,4 +122,72 @@ class OutputRunnerTest < Test::Unit::TestCase
122
122
  end
123
123
  end
124
124
 
125
+ context "A runner where the environment is overridden using the :set option" do
126
+ setup do
127
+ @output = Whenever.cron :set => 'environment=serious', :string => \
128
+ <<-file
129
+ set :environment, :silly
130
+ set :path, '/my/path'
131
+ every 2.hours do
132
+ runner "blahblah"
133
+ end
134
+ file
135
+ end
136
+
137
+ should "output the runner using the override environment" do
138
+ assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
139
+ end
140
+ end
141
+
142
+ context "A runner where the environment and path are overridden using the :set option" do
143
+ setup do
144
+ @output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
145
+ <<-file
146
+ set :environment, :silly
147
+ set :path, '/silly/path'
148
+ every 2.hours do
149
+ runner "blahblah"
150
+ end
151
+ file
152
+ end
153
+
154
+ should "output the runner using the overridden path and environment" do
155
+ assert_match two_hours + ' /serious/path/script/runner -e serious "blahblah"', @output
156
+ end
157
+ end
158
+
159
+ context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
160
+ setup do
161
+ @output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
162
+ <<-file
163
+ set :environment, :silly
164
+ set :path, '/silly/path'
165
+ every 2.hours do
166
+ runner "blahblah"
167
+ end
168
+ file
169
+ end
170
+
171
+ should "output the runner using the overridden path and environment" do
172
+ assert_match two_hours + ' /serious/path/script/runner -e serious "blahblah"', @output
173
+ end
174
+ end
175
+
176
+ context "A runner where the environment is overridden using the :set option but no value is given" do
177
+ setup do
178
+ @output = Whenever.cron :set => ' environment=', :string => \
179
+ <<-file
180
+ set :environment, :silly
181
+ set :path, '/silly/path'
182
+ every 2.hours do
183
+ runner "blahblah"
184
+ end
185
+ file
186
+ end
187
+
188
+ should "output the runner using the original environmnet" do
189
+ assert_match two_hours + ' /silly/path/script/runner -e silly "blahblah"', @output
190
+ end
191
+ end
192
+
125
193
  end
data/whenever.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{whenever}
5
- s.version = "0.2.2"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Javan Makhmali"]
9
- s.date = %q{2009-04-30}
9
+ s.date = %q{2009-06-02}
10
10
  s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
11
11
  s.email = %q{javan@javan.us}
12
12
  s.executables = ["whenever", "wheneverize"]
13
13
  s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "README.rdoc"]
14
- s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Rakefile", "README.rdoc", "test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec", "Manifest"]
14
+ s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Manifest", "Rakefile", "README.rdoc", "test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec"]
15
15
  s.has_rdoc = true
16
16
  s.homepage = %q{http://github.com/javan/whenever}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: javan-whenever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-30 00:00:00 -07:00
12
+ date: 2009-06-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - lib/outputs/cron.rb
67
67
  - lib/version.rb
68
68
  - lib/whenever.rb
69
+ - Manifest
69
70
  - Rakefile
70
71
  - README.rdoc
71
72
  - test/command_line_test.rb
@@ -76,7 +77,6 @@ files:
76
77
  - test/output_runner_test.rb
77
78
  - test/test_helper.rb
78
79
  - whenever.gemspec
79
- - Manifest
80
80
  has_rdoc: true
81
81
  homepage: http://github.com/javan/whenever
82
82
  post_install_message: