chrono 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b2654829b86a6c6e8ad37744e19fc96408a5ac9f
4
- data.tar.gz: a50cb68f2dcd05bafd92ce0c2f6ff6cc5df4e0f6
2
+ SHA256:
3
+ metadata.gz: 046fa468703ffbd8c7c77b1767853c5db8e518c6affbc0b2a84d466cb15492b5
4
+ data.tar.gz: 2128582a3bf2822dc3eab8cdf27e159fb4bd193ed896b4cea36309e4fec5516e
5
5
  SHA512:
6
- metadata.gz: 6d32b10ee846d5a185dcff6a05bb0dc11deee5cbb58ac9e68d32032fe26d04e80708be98da15b574abe7016d39059b19aba2685a73584ce3664859558a35a519
7
- data.tar.gz: 81d639646d8c41744af982fc1bb616df02fd3d3514be8e09897b2306253f489e83ed8da3bb0c90fc013225c53e5c5fee885f73ff859227a43ad9ee6ae25e7543
6
+ metadata.gz: 46dbbf74bd81f5f5177109660e85edb88fb65fcf561947ea924f0fe158e5c117fb9b91a9c9b8a8202d425f3e0e6fdb43ef506912ce4207ba0bb0e4cb5648ae23
7
+ data.tar.gz: 5891051f8983853fbafb88e171bfdb315653e43be2165cbb837e52a705e1a6a3696f441eee41b0b9842cbe7b8f40fbf430625016fa77e1c172c4d2a8eb68b6cb
@@ -0,0 +1,22 @@
1
+ name: test
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby:
15
+ - 2.7.2
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,20 +1,77 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.5.0
6
+
7
+ ### Added
8
+
9
+ - Add support for activesupport 7 (thx @unasuke).
10
+
11
+ ### Changed
12
+
13
+ - Drop support of activesupport below 5.2.
14
+
15
+ ## 0.4.0
16
+
17
+ ### Changed
18
+
19
+ - Raise ArgumentError on inifinite loop detected (thx @nurse).
20
+
21
+ ## 0.3.0
22
+
23
+ ### Fixed
24
+
25
+ - Fix bug on day and wday specs.
26
+
27
+ ## 0.2.0
28
+
29
+ ### Added
30
+
31
+ - Support some alias field names.
32
+
33
+ ### Changed
34
+
35
+ - Add more strict validations.
36
+
1
37
  ## 0.1.0
2
- - Raise errors on invalid fields (thx @eagletmt)
38
+
39
+ ### Changed
40
+
41
+ - Raise errors on invalid fields (thx @eagletmt).
3
42
 
4
43
  ## 0.0.6
5
- - Support ActiveSupport 3 and 4
44
+
45
+ ### Changed
46
+
47
+ - Support ActiveSupport 3 and 4.
6
48
 
7
49
  ## 0.0.5
8
- - Fix missing version dependency on ActiveSupport 4
50
+
51
+ ### Changed
52
+
53
+ - Fix missing version dependency on ActiveSupport 4.
9
54
 
10
55
  ## 0.0.4
11
- - Add extra 1sec sleep to adjust to exact minute
56
+
57
+ ### Changed
58
+
59
+ - Add extra 1sec sleep to adjust to exact minute.
12
60
 
13
61
  ## 0.0.3
14
- - Schedule more accurate second
62
+
63
+ ### Changed
64
+
65
+ - Schedule more accurate second.
15
66
 
16
67
  ## 0.0.2
17
- - Chrono::Trigger was added
68
+
69
+ ### Added
70
+
71
+ - Chrono::Trigger was added.
18
72
 
19
73
  ## 0.0.1
20
- - Chrono::Iterator was added
74
+
75
+ ### Added
76
+
77
+ - Chrono::Iterator was added.
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Chrono [![Build Status](https://travis-ci.org/r7kamura/chrono.png)](https://travis-ci.org/r7kamura/chrono) [![Code Climate](https://codeclimate.com/github/r7kamura/chrono.png)](https://codeclimate.com/github/r7kamura/chrono) [![Code Climate](https://codeclimate.com/github/r7kamura/chrono/coverage.png)](https://codeclimate.com/github/r7kamura/chrono)
1
+ # Chrono
2
+
3
+ [![test](https://github.com/r7kamura/chrono/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/chrono/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/chrono.svg)](https://rubygems.org/gems/chrono)
2
5
 
3
6
  Provides a chain of logics about chronology.
4
7
 
data/chrono.gemspec CHANGED
@@ -16,10 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "activesupport"
19
+ spec.add_dependency "activesupport", '>= 5.2'
20
20
  spec.add_development_dependency "bundler"
21
- spec.add_development_dependency "codeclimate-test-reporter"
22
21
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "2.14.1"
24
- spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "rspec", "~> 3.4.0"
25
23
  end
@@ -1,8 +1,35 @@
1
1
  module Chrono
2
2
  module Fields
3
3
  class Month < Base
4
+ TABLE = {
5
+ 'jan' => '1',
6
+ 'feb' => '2',
7
+ 'mar' => '3',
8
+ 'apr' => '4',
9
+ 'may' => '5',
10
+ 'jun' => '6',
11
+ 'jul' => '7',
12
+ 'aug' => '8',
13
+ 'sep' => '9',
14
+ 'oct' => '10',
15
+ 'nov' => '11',
16
+ 'dec' => '12',
17
+ }
18
+ REGEXP = %r<\A(?<step>(?:\*|(?:(?<atom>\d+||jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)(?:-\g<atom>)?))(?:/\d+)?)(?:,\g<step>)*\z>ix
19
+
20
+ def initialize(source)
21
+ unless REGEXP =~ source
22
+ raise InvalidField.new('Unparsable field', source)
23
+ end
24
+ @source = source
25
+ end
26
+
4
27
  private
5
28
 
29
+ def interpolated
30
+ super.downcase.gsub(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/, TABLE)
31
+ end
32
+
6
33
  def range
7
34
  1..12
8
35
  end
@@ -1,8 +1,31 @@
1
1
  module Chrono
2
2
  module Fields
3
3
  class Wday < Base
4
+ TABLE = {
5
+ '7' => '0',
6
+ 'sun' => '0',
7
+ 'mon' => '1',
8
+ 'tue' => '2',
9
+ 'wed' => '3',
10
+ 'thu' => '4',
11
+ 'fri' => '5',
12
+ 'sat' => '6',
13
+ }
14
+ REGEXP = %r<\A(?:(?<step>(?:\*|(?:(?<atom>\d+|sun|mon|tue|wed|thu|fri|sat)(?:-\g<atom>)?))(?:/\d+)?)(?:,\g<step>)*)\z>ix
15
+
16
+ def initialize(source)
17
+ unless REGEXP =~ source
18
+ raise InvalidField.new('Unparsable field', source)
19
+ end
20
+ @source = source
21
+ end
22
+
4
23
  private
5
24
 
25
+ def interpolated
26
+ super.downcase.gsub(/7|sun|mon|tue|wed|thu|fri|sat/, TABLE)
27
+ end
28
+
6
29
  def range
7
30
  0..6
8
31
  end
@@ -1,13 +1,5 @@
1
+ require "active_support"
1
2
  require "active_support/core_ext/numeric/time"
2
- require "active_support/version"
3
-
4
- if ActiveSupport::VERSION::MAJOR >= 4
5
- require "active_support/core_ext/date"
6
- require "active_support/core_ext/time"
7
- else
8
- require "active_support/core_ext/date/calculations"
9
- require "active_support/core_ext/time/calculations"
10
- end
11
3
 
12
4
  module Chrono
13
5
  class NextTime
@@ -21,22 +13,24 @@ module Chrono
21
13
  end
22
14
 
23
15
  def to_time
24
- loop do
16
+ # the longest cycle is 4 years (leap year)
17
+ # Note that the combination of day-month and wday is OR
18
+ max_time = time + (365 * 3 + 366).days
19
+ while @time < max_time
25
20
  case
26
21
  when !scheduled_in_this_month?
27
22
  carry_month
28
23
  when !scheduled_in_this_day?
29
24
  carry_day
30
- when !scheduled_in_this_wday?
31
- carry_day
32
25
  when !scheduled_in_this_hour?
33
26
  carry_hour
34
27
  when !scheduled_in_this_minute?
35
28
  carry_minute
36
29
  else
37
- break time
30
+ return @time
38
31
  end
39
32
  end
33
+ raise ArgumentError, "invalid cron string '#{@source}'"
40
34
  end
41
35
 
42
36
  private
@@ -54,11 +48,19 @@ module Chrono
54
48
  end
55
49
 
56
50
  def scheduled_in_this_day?
57
- schedule.days.include?(time.day)
58
- end
59
-
60
- def scheduled_in_this_wday?
61
- schedule.wdays.include?(time.wday)
51
+ if schedule.days?
52
+ if schedule.wdays?
53
+ schedule.days.include?(time.day) || schedule.wdays.include?(time.wday)
54
+ else
55
+ schedule.days.include?(time.day)
56
+ end
57
+ else
58
+ if schedule.wdays?
59
+ schedule.wdays.include?(time.wday)
60
+ else
61
+ true
62
+ end
63
+ end
62
64
  end
63
65
 
64
66
  def scheduled_in_this_hour?
@@ -1,8 +1,20 @@
1
1
  module Chrono
2
2
  class Schedule
3
3
  attr_reader :source
4
+ TABLE = {
5
+ '@yearly' => %w"0 0 1 1 *",
6
+ '@annually' => %w"0 0 1 1 *",
7
+ '@monthly' => %w"0 0 1 * *",
8
+ '@weekly' => %w"0 0 * * 0",
9
+ '@daily' => %w"0 0 * * *",
10
+ '@hourly' => %w"0 * * * *",
11
+ }
4
12
 
5
13
  def initialize(source)
14
+ if @fields = TABLE[source]
15
+ elsif %r<\A[ \t]*(?:(?<field>\S+)[ \t]+){4}\g<field>[ \t]*\z> !~ source
16
+ raise Chrono::Fields::Base::InvalidField.new('invalid source', source)
17
+ end
6
18
  @source = source
7
19
  end
8
20
 
@@ -26,6 +38,14 @@ module Chrono
26
38
  Fields::Wday.new(fields[4]).to_a
27
39
  end
28
40
 
41
+ def days?
42
+ fields[2] != '*'
43
+ end
44
+
45
+ def wdays?
46
+ fields[4] != '*'
47
+ end
48
+
29
49
  private
30
50
 
31
51
  def fields
@@ -1,3 +1,3 @@
1
1
  module Chrono
2
- VERSION = "0.1.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -22,27 +22,34 @@ describe Chrono::Iterator do
22
22
  "2000-01-04 00:00:00", "2000-01-04 00:01:00", "* * * * 2,3",
23
23
  "2000-01-01 00:01:00", "2000-01-01 00:04:00", "1-20/3 * * * *",
24
24
  "2000-01-01 00:20:00", "2000-01-01 01:01:00", "1-20/3 * * * *",
25
+ "2000-01-01 00:00:00", "2000-01-03 00:00:00", "0 0 1,15 * 1",
26
+ "2000-01-01 00:00:00", "2000-01-05 00:00:00", "0 0 5,15,25 * 5",
27
+ "2000-02-29 00:00:01", "2004-02-29 00:00:00", "0 0 29 2 *",
25
28
  ].each_slice(3) do |from, to, source|
26
29
  it "ticks #{from} to #{to} by #{source}" do
27
30
  now = Time.parse(from)
28
- described_class.new(source, now: now).next.should == Time.parse(to)
31
+ expect(described_class.new(source, now: now).next).to eq(Time.parse(to))
29
32
  end
33
+ end
30
34
 
31
- it 'raises error when empty range is given' do
32
- expect { described_class.new('5-0 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
33
- end
35
+ it 'raises error when empty range is given' do
36
+ expect { described_class.new('5-0 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
37
+ end
34
38
 
35
- it 'raises error when too large upper is given' do
36
- expect { described_class.new('5-60 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
37
- end
39
+ it 'raises error when too large upper is given' do
40
+ expect { described_class.new('5-60 * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
41
+ end
38
42
 
39
- it 'raises error when too low lower is given' do
40
- expect { described_class.new('* * 0 * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
41
- end
43
+ it 'raises error when too low lower is given' do
44
+ expect { described_class.new('* * 0 * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
45
+ end
42
46
 
43
- it 'raises error when unparsable field is given' do
44
- expect { described_class.new('a-z * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
45
- end
47
+ it 'raises error when unparsable field is given' do
48
+ expect { described_class.new('a-z * * * *').next }.to raise_error(Chrono::Fields::Base::InvalidField)
49
+ end
50
+
51
+ it 'raises error when unparsable field is given' do
52
+ expect { described_class.new('* * 31 11 *').next }.to raise_error(ArgumentError)
46
53
  end
47
54
  end
48
55
  end
@@ -0,0 +1,268 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chrono::Schedule do
4
+ let (:schedule) { Chrono::Schedule.new(source) }
5
+
6
+ describe '.new' do
7
+ context 'valid source' do
8
+ subject { Chrono::Schedule.new("\t*\t*\t*\t*\t*\t") }
9
+ it { is_expected.to be_a(Chrono::Schedule) }
10
+ end
11
+ context 'six fields' do
12
+ subject { Chrono::Schedule.new('* * * * * *') }
13
+ it { expect{subject.minutes}.to raise_error(Chrono::Fields::Base::InvalidField) }
14
+ end
15
+ context '@yearly' do
16
+ subject { Chrono::Schedule.new('@yearly') }
17
+ it do
18
+ expect(subject.minutes).to eq([0])
19
+ expect(subject.hours).to eq([0])
20
+ expect(subject.days).to eq([1])
21
+ expect(subject.months).to eq([1])
22
+ expect(subject.wdays).to eq(7.times.to_a)
23
+ end
24
+ end
25
+ context '@annually' do
26
+ subject { Chrono::Schedule.new('@annually') }
27
+ it do
28
+ expect(subject.minutes).to eq([0])
29
+ expect(subject.hours).to eq([0])
30
+ expect(subject.days).to eq([1])
31
+ expect(subject.months).to eq([1])
32
+ expect(subject.wdays).to eq(7.times.to_a)
33
+ end
34
+ end
35
+ context '@monthly' do
36
+ subject { Chrono::Schedule.new('@monthly') }
37
+ it do
38
+ expect(subject.minutes).to eq([0])
39
+ expect(subject.hours).to eq([0])
40
+ expect(subject.days).to eq([1])
41
+ expect(subject.months).to eq((1..12).to_a)
42
+ expect(subject.wdays).to eq(7.times.to_a)
43
+ end
44
+ end
45
+ context '@weekly' do
46
+ subject { Chrono::Schedule.new('@weekly') }
47
+ it do
48
+ expect(subject.minutes).to eq([0])
49
+ expect(subject.hours).to eq([0])
50
+ expect(subject.days).to eq((1..31).to_a)
51
+ expect(subject.months).to eq((1..12).to_a)
52
+ expect(subject.wdays).to eq([0])
53
+ end
54
+ end
55
+ context '@daily' do
56
+ subject { Chrono::Schedule.new('@daily') }
57
+ it do
58
+ expect(subject.minutes).to eq([0])
59
+ expect(subject.hours).to eq([0])
60
+ expect(subject.days).to eq((1..31).to_a)
61
+ expect(subject.months).to eq((1..12).to_a)
62
+ expect(subject.wdays).to eq(7.times.to_a)
63
+ end
64
+ end
65
+ context '@hourly' do
66
+ subject { Chrono::Schedule.new('@hourly') }
67
+ it do
68
+ expect(subject.minutes).to eq([0])
69
+ expect(subject.hours).to eq(24.times.to_a)
70
+ expect(subject.days).to eq((1..31).to_a)
71
+ expect(subject.months).to eq((1..12).to_a)
72
+ expect(subject.wdays).to eq(7.times.to_a)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#minutes' do
78
+ subject { schedule.minutes }
79
+ context "'0 0 * * *'" do
80
+ let (:source){ '0 0 * * *' }
81
+ it { is_expected.to eq [0] }
82
+ end
83
+ context "'59 0 * * *'" do
84
+ let (:source){ '59 0 * * *' }
85
+ it { is_expected.to eq [59] }
86
+ end
87
+ context "'60 0 * * *'" do
88
+ let (:source){ '60 0 * * *' }
89
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
90
+ end
91
+ end
92
+
93
+ describe '#hours' do
94
+ subject { schedule.hours }
95
+ context "'0 0 * * *'" do
96
+ let (:source){ '0 0 * * *' }
97
+ it { is_expected.to eq [0] }
98
+ end
99
+ context "'0 23 * * *'" do
100
+ let (:source){ '0 23 * * *' }
101
+ it { is_expected.to eq [23] }
102
+ end
103
+ context "'0 24 * * *'" do
104
+ let (:source){ '0 24 * * *' }
105
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
106
+ end
107
+ end
108
+
109
+ describe '#days' do
110
+ subject { schedule.days }
111
+ context 'day: 1' do
112
+ let (:source){ '0 0 1 * *' }
113
+ it { is_expected.to eq [1] }
114
+ end
115
+ context 'day: 31' do
116
+ let (:source){ '0 0 31 * *' }
117
+ it { is_expected.to eq [31] }
118
+ end
119
+ context 'day" 0' do
120
+ let (:source){ '0 0 0 * *' }
121
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
122
+ end
123
+ context 'day: 32' do
124
+ let (:source){ '0 0 32 * *' }
125
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
126
+ end
127
+ end
128
+
129
+ describe '#months' do
130
+ subject { schedule.months }
131
+ context 'month: 1' do
132
+ let (:source){ '0 0 1 1 *' }
133
+ it { is_expected.to eq [1] }
134
+ end
135
+ context 'month: 12' do
136
+ let (:source){ '0 0 1 12 0' }
137
+ it { is_expected.to eq [12] }
138
+ end
139
+ context 'month: 0' do
140
+ let (:source){ '0 0 1 0 *' }
141
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
142
+ end
143
+ context 'month: 13' do
144
+ let (:source){ '0 0 13 0 *' }
145
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
146
+ end
147
+ context 'month: Jan' do
148
+ let (:source){ '0 0 1 Jan 0' }
149
+ it { is_expected.to eq [1] }
150
+ end
151
+ context 'month: Feb' do
152
+ let (:source){ '0 0 1 Feb 0' }
153
+ it { is_expected.to eq [2] }
154
+ end
155
+ context 'month: Mar' do
156
+ let (:source){ '0 0 1 Mar 0' }
157
+ it { is_expected.to eq [3] }
158
+ end
159
+ context 'month: Apr' do
160
+ let (:source){ '0 0 1 Apr 0' }
161
+ it { is_expected.to eq [4] }
162
+ end
163
+ context 'month: May' do
164
+ let (:source){ '0 0 1 May 0' }
165
+ it { is_expected.to eq [5] }
166
+ end
167
+ context 'month: Jun' do
168
+ let (:source){ '0 0 1 Jun 0' }
169
+ it { is_expected.to eq [6] }
170
+ end
171
+ context 'month: Jul' do
172
+ let (:source){ '0 0 1 Jul 0' }
173
+ it { is_expected.to eq [7] }
174
+ end
175
+ context 'month: Aug' do
176
+ let (:source){ '0 0 1 Aug 0' }
177
+ it { is_expected.to eq [8] }
178
+ end
179
+ context 'month: Sep' do
180
+ let (:source){ '0 0 1 Sep 0' }
181
+ it { is_expected.to eq [9] }
182
+ end
183
+ context 'month: Oct' do
184
+ let (:source){ '0 0 1 Oct 0' }
185
+ it { is_expected.to eq [10] }
186
+ end
187
+ context 'month: Nov' do
188
+ let (:source){ '0 0 1 Nov 0' }
189
+ it { is_expected.to eq [11] }
190
+ end
191
+ context 'month: Dec' do
192
+ let (:source){ '0 0 1 Dec 0' }
193
+ it { is_expected.to eq [12] }
194
+ end
195
+ context 'month: Mar-Dec/3' do
196
+ let (:source){ '0 0 1 Mar-Dec/3 0' }
197
+ it { is_expected.to eq [3,6,9,12] }
198
+ end
199
+ context 'month: Mar,Jun,Sep,Dec' do
200
+ let (:source){ '0 0 1 Mar,Jun,Sep,Dec/3 0' }
201
+ it { is_expected.to eq [3,6,9,12] }
202
+ end
203
+ context 'month: January' do
204
+ let (:source){ '0 0 1 January 0' }
205
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
206
+ end
207
+ context 'month: Abc' do
208
+ let (:source){ '0 0 1 Abc 0' }
209
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
210
+ end
211
+ end
212
+
213
+ describe '#wdays' do
214
+ subject { schedule.wdays }
215
+ context 'wdays: 0' do
216
+ let (:source){ '0 0 * * 0' }
217
+ it { is_expected.to eq [0] }
218
+ end
219
+ context 'wdays: 6' do
220
+ let (:source){ '0 0 * * 6' }
221
+ it { is_expected.to eq [6] }
222
+ end
223
+ context 'wdays: 7' do
224
+ let (:source){ '0 0 * * 7' }
225
+ it { is_expected.to eq [0] }
226
+ end
227
+ context 'wdays: 8' do
228
+ let (:source){ '0 0 * * 8' }
229
+ it { expect{subject}.to raise_error(Chrono::Fields::Base::InvalidField) }
230
+ end
231
+ context 'wdays: sun' do
232
+ let (:source){ '0 0 * * sun' }
233
+ it { is_expected.to eq [0] }
234
+ end
235
+ context 'wdays: mon' do
236
+ let (:source){ '0 0 * * mon' }
237
+ it { is_expected.to eq [1] }
238
+ end
239
+ context 'wdays: tue' do
240
+ let (:source){ '0 0 * * tue' }
241
+ it { is_expected.to eq [2] }
242
+ end
243
+ context 'wdays: wed' do
244
+ let (:source){ '0 0 * * wed' }
245
+ it { is_expected.to eq [3] }
246
+ end
247
+ context 'wdays: Thu' do
248
+ let (:source){ '0 0 * * Thu' }
249
+ it { is_expected.to eq [4] }
250
+ end
251
+ context 'wdays: FRI' do
252
+ let (:source){ '0 0 * * FRI' }
253
+ it { is_expected.to eq [5] }
254
+ end
255
+ context 'wdays: Sat' do
256
+ let (:source){ '0 0 * * Sat' }
257
+ it { is_expected.to eq [6] }
258
+ end
259
+ context 'wdays: Sun-Sat' do
260
+ let (:source){ '0 0 * * Sun-Sat' }
261
+ it { is_expected.to eq [0,1,2,3,4,5,6] }
262
+ end
263
+ context 'wdays: Sun,Sat' do
264
+ let (:source){ '0 0 * * Sun,Sat' }
265
+ it { is_expected.to eq [0,6] }
266
+ end
267
+ end
268
+ end
@@ -15,8 +15,8 @@ describe Chrono::Trigger do
15
15
 
16
16
  describe "#once" do
17
17
  it "waits till scheduled time and then triggers a given job only once" do
18
- block.should_receive(:call)
19
- trigger.should_receive(:sleep)
18
+ expect(block).to receive(:call)
19
+ expect(trigger).to receive(:sleep)
20
20
  trigger.once
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ describe Chrono::Trigger do
24
24
  # Stub Trigger#loop behavior to avoid blocking main process.
25
25
  describe "#run" do
26
26
  before do
27
- trigger.stub(:loop) do |&block|
27
+ allow(trigger).to receive(:loop) do |&block|
28
28
  2.times do
29
29
  block.call
30
30
  end
@@ -32,8 +32,8 @@ describe Chrono::Trigger do
32
32
  end
33
33
 
34
34
  it "waits till scheduled time and then triggers a given job periodically" do
35
- block.should_receive(:call).twice
36
- trigger.should_receive(:sleep).twice
35
+ expect(block).to receive(:call).twice
36
+ expect(trigger).to receive(:sleep).twice
37
37
  trigger.run
38
38
  end
39
39
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,7 @@
1
- require "simplecov"
2
- SimpleCov.start
3
-
4
- if ENV["CI"]
5
- require "codeclimate-test-reporter"
6
- CodeClimate::TestReporter.start
7
- end
8
-
9
1
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
10
2
  require "chrono"
11
3
 
12
4
  RSpec.configure do |config|
13
- config.treat_symbols_as_metadata_keys_with_true_values = true
14
5
  config.run_all_when_everything_filtered = true
15
6
  config.filter_run :focus
16
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrono
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: codeclimate-test-reporter
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,30 +56,16 @@ dependencies:
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - '='
74
- - !ruby/object:Gem::Version
75
- version: 2.14.1
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '='
81
- - !ruby/object:Gem::Version
82
- version: 2.14.1
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
59
+ - - "~>"
88
60
  - !ruby/object:Gem::Version
89
- version: '0'
61
+ version: 3.4.0
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - ">="
66
+ - - "~>"
95
67
  - !ruby/object:Gem::Version
96
- version: '0'
68
+ version: 3.4.0
97
69
  description:
98
70
  email:
99
71
  - r7kamura@gmail.com
@@ -101,8 +73,8 @@ executables: []
101
73
  extensions: []
102
74
  extra_rdoc_files: []
103
75
  files:
76
+ - ".github/workflows/test.yml"
104
77
  - ".gitignore"
105
- - ".travis.yml"
106
78
  - CHANGELOG.md
107
79
  - Gemfile
108
80
  - LICENSE.txt
@@ -122,6 +94,7 @@ files:
122
94
  - lib/chrono/trigger.rb
123
95
  - lib/chrono/version.rb
124
96
  - spec/chrono/iterator_spec.rb
97
+ - spec/chrono/schedule_spec.rb
125
98
  - spec/chrono/trigger_spec.rb
126
99
  - spec/spec_helper.rb
127
100
  homepage: https://github.com/r7kamura/chrono
@@ -143,13 +116,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
116
  - !ruby/object:Gem::Version
144
117
  version: '0'
145
118
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.4.5
119
+ rubygems_version: 3.1.4
148
120
  signing_key:
149
121
  specification_version: 4
150
122
  summary: Provides a chain of logics about chronology.
151
123
  test_files:
152
124
  - spec/chrono/iterator_spec.rb
125
+ - spec/chrono/schedule_spec.rb
153
126
  - spec/chrono/trigger_spec.rb
154
127
  - spec/spec_helper.rb
155
- has_rdoc:
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- branches:
5
- only:
6
- - master
7
- env:
8
- global:
9
- secure: bzOuKK2sEcdWchOeiS5VgKIj8R6ZFZLtmlJ3aENdYAXcrrVW+1XKAGQlT3NxH5G2EloV8nNPOX8oNXbYjs81AvEEdjZGRMYUnC59GbvtL+2zQgG77yq5xI/UXypuBQIzUBhzrwFMImSAltKsdlbsrVUtl7x8Arg1HajcMbEsg9Y=