insrc-whenever 0.5.0 → 0.5.1

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.
@@ -1,7 +1,7 @@
1
1
  module Whenever
2
2
  class Job
3
3
 
4
- attr_accessor :at, :output_redirection
4
+ attr_accessor :at, :output_redirection, :raw_syntex
5
5
 
6
6
  def initialize(options = {})
7
7
  @options = options
@@ -10,6 +10,7 @@ module Whenever
10
10
  @output_redirection = options.has_key?(:output) ? options[:output] : :not_set
11
11
  @options[:environment] ||= :production
12
12
  @options[:path] ||= Whenever.path
13
+ @raw_syntex = options[:raw_syntex] || false
13
14
  end
14
15
 
15
16
  def output
@@ -42,6 +42,12 @@ module Whenever
42
42
  yield
43
43
  end
44
44
 
45
+ def cron(frequency, options = {})
46
+ @current_time_scope = frequency
47
+ @options = options.merge(:raw_syntex => true)
48
+ yield
49
+ end
50
+
45
51
  def job_type(name, template)
46
52
  class_eval do
47
53
  define_method(name) do |task, *args|
@@ -5,11 +5,12 @@ module Whenever
5
5
 
6
6
  attr_accessor :time, :task
7
7
 
8
- def initialize(time = nil, task = nil, at = nil, output_redirection = nil)
8
+ def initialize(time = nil, task = nil, at = nil, output_redirection = nil, raw_syntex = false)
9
9
  @time = time
10
10
  @task = task
11
11
  @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
12
12
  @output_redirection = output_redirection
13
+ @raw_syntex = raw_syntex
13
14
  end
14
15
 
15
16
  def self.enumerate(item)
@@ -25,7 +26,7 @@ module Whenever
25
26
  def self.output(times, job)
26
27
  enumerate(times).each do |time|
27
28
  enumerate(job.at).each do |at|
28
- yield new(time, job.output, at, job.output_redirection).output
29
+ yield new(time, job.output, at, job.output_redirection, job.raw_syntex).output
29
30
  end
30
31
  end
31
32
  end
@@ -35,10 +36,14 @@ module Whenever
35
36
  end
36
37
 
37
38
  def time_in_cron_syntax
38
- case @time
39
- when Symbol then parse_symbol
40
- when String then parse_as_string
41
- else parse_time
39
+ if @raw_syntex
40
+ @time
41
+ else
42
+ case @time
43
+ when Symbol then parse_symbol
44
+ when String then parse_as_string
45
+ else parse_time
46
+ end
42
47
  end
43
48
  end
44
49
 
@@ -199,6 +199,12 @@ class CronTest < Test::Unit::TestCase
199
199
  end
200
200
  end
201
201
  end
202
+
203
+ context "When parsing time using raw syntex" do
204
+ should "return a raw syntex cron format" do
205
+ assert_equal '*/2 9-15 * * 1-5', parse_time("*/2 9-15 * * 1-5", nil, nil, true)
206
+ end
207
+ end
202
208
 
203
209
  private
204
210
 
@@ -219,8 +225,8 @@ private
219
225
  assert_equal expected, cron.split(' ')[0]
220
226
  end
221
227
 
222
- def parse_time(time = nil, task = nil, at = nil)
223
- Whenever::Output::Cron.new(time, task, at).time_in_cron_syntax
228
+ def parse_time(time = nil, task = nil, at = nil, raw_syntex = false)
229
+ Whenever::Output::Cron.new(time, task, at, nil, raw_syntex).time_in_cron_syntax
224
230
  end
225
231
 
226
232
  end
@@ -234,4 +234,19 @@ class OutputAtTest < Test::Unit::TestCase
234
234
  assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
235
235
  end
236
236
  end
237
+
238
+ context "cron raw syntext" do
239
+ setup do
240
+ @output = Whenever.cron \
241
+ <<-file
242
+ cron "*/2 9-15 * * 1-5" do
243
+ command "blahblah"
244
+ end
245
+ file
246
+ end
247
+
248
+ should "output the command using that time" do
249
+ assert_match '*/2 9-15 * * 1-5 blahblah', @output
250
+ end
251
+ end
237
252
  end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{insrc-whenever}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["IN SRC Studio"]
12
- s.date = %q{2010-06-28}
13
- s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
11
+ s.authors = ["IN-SRC Studio"]
12
+ s.date = %q{2010-07-30}
13
+ s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs. Support cron raw syntex.}
14
14
  s.email = %q{elanmeng@in-src.com}
15
15
  s.executables = ["whenever", "wheneverize"]
16
16
  s.extra_rdoc_files = [
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  "test/test_helper.rb",
45
45
  "whenever.gemspec"
46
46
  ]
47
- s.homepage = %q{http://github.com/javan/whenever}
47
+ s.homepage = %q{http://github.com/dreamwords/whenever}
48
48
  s.rdoc_options = ["--charset=UTF-8"]
49
49
  s.require_paths = ["lib"]
50
50
  s.rubygems_version = %q{1.3.6}
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insrc-whenever
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
- - IN SRC Studio
13
+ - IN-SRC Studio
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-28 00:00:00 +08:00
18
+ date: 2010-07-30 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 0.2.3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- description: Clean ruby syntax for defining and deploying messy cron jobs.
37
+ description: Clean ruby syntax for defining and deploying messy cron jobs. Support cron raw syntex.
38
38
  email: elanmeng@in-src.com
39
39
  executables:
40
40
  - whenever
@@ -71,7 +71,7 @@ files:
71
71
  - test/test_helper.rb
72
72
  - whenever.gemspec
73
73
  has_rdoc: true
74
- homepage: http://github.com/javan/whenever
74
+ homepage: http://github.com/dreamwords/whenever
75
75
  licenses: []
76
76
 
77
77
  post_install_message: