cronut 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE.md +21 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/bin/cronut +17 -0
- data/cronut.gemspec +26 -0
- data/lib/cronut.rb +18 -0
- data/lib/cronut/expression.rb +36 -0
- data/lib/cronut/parser.rb +22 -0
- data/lib/cronut/parser/any.rb +11 -0
- data/lib/cronut/parser/base.rb +35 -0
- data/lib/cronut/parser/exact.rb +11 -0
- data/lib/cronut/parser/list.rb +13 -0
- data/lib/cronut/parser/range.rb +15 -0
- data/lib/cronut/parser/step.rb +21 -0
- data/lib/cronut/segment/base.rb +30 -0
- data/lib/cronut/segment/day.rb +15 -0
- data/lib/cronut/segment/hour.rb +15 -0
- data/lib/cronut/segment/minute.rb +15 -0
- data/lib/cronut/segment/month.rb +15 -0
- data/lib/cronut/segment/weekday.rb +15 -0
- data/lib/cronut/version.rb +3 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c43ded70bbed5f6cb9b5957274437899b14449c
|
4
|
+
data.tar.gz: d9edc9ac3bc194ea8b37c4dd7e5c24961f41f727
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40cc2971b966b3b88d28631b16dee5caea14c776b6b948fc0319cd74ec7047c1e722f75453372ae03f6ece15fff5d2cb077202292ab620707e688c8d38d11a53
|
7
|
+
data.tar.gz: fd81cc22af64660cfdce0fb22c7a20d15bc15b9ae2f587d1fefc9624a444657f5d5114bea7fb8e212946992e8988aaa40acf601b59b0aa96645e0394edff8b52
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Josh McMillan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Cronut
|
2
|
+
|
3
|
+
<img align="right" width="150" src="https://upload.wikimedia.org/wikipedia/commons/9/99/Cronut.jpg">
|
4
|
+
|
5
|
+
Cronut is a tool for taking a cron expression (e.g. `* * * * * /bin/yes`) and outputting the times at which that cron expression will run. It supports most standard Vixie cron syntax, with some exceptions – see [known issues](#known-issues).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Ensure you have Ruby 2.3 or higher installed
|
10
|
+
1. Run `gem install cronut`
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
There are two ways to use Cronut:
|
15
|
+
|
16
|
+
### As a command-line tool
|
17
|
+
|
18
|
+
To use Cronut as a command-line tool and get human-readable representations of a cron expression, simply run:
|
19
|
+
|
20
|
+
```
|
21
|
+
cronut <your_cron_expression>
|
22
|
+
```
|
23
|
+
|
24
|
+
For example:
|
25
|
+
|
26
|
+
```
|
27
|
+
cronut '*/15 0 1,15 * 1-5 /usr/bin/find'
|
28
|
+
```
|
29
|
+
|
30
|
+
will output:
|
31
|
+
|
32
|
+
```
|
33
|
+
minute 0 15 30 45
|
34
|
+
hour 0
|
35
|
+
day of month 1 15
|
36
|
+
month 1 2 3 4 5 6 7 8 9 10 11 12
|
37
|
+
day of week 1 2 3 4 5
|
38
|
+
command /usr/bin/find
|
39
|
+
```
|
40
|
+
|
41
|
+
### As a library
|
42
|
+
|
43
|
+
After you've required Cronut in your application (via `require 'cronut'` or your Gemfile), it can be used like so:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
expression = Cronut::Expression.new('* * * * * /bin/yes')
|
47
|
+
=> #<Cronut::Expression:0x007f975d06c8d0>
|
48
|
+
|
49
|
+
expression.weekday.possibilities
|
50
|
+
=> [0, 1, 2, 3, 4, 5, 6]
|
51
|
+
|
52
|
+
expression.command
|
53
|
+
=> "/bin/yes"
|
54
|
+
```
|
55
|
+
|
56
|
+
## Known Issues
|
57
|
+
|
58
|
+
The following (largely non-standard) features of some cron parsers are currently unsupported:
|
59
|
+
|
60
|
+
1. Shorthand macros (e.g. `@yearly`, `@monthly`, `@daily`)
|
61
|
+
1. Compositions of lists, ranges and steps (e.g. `1-2,3,*/4`)
|
62
|
+
1. Alternative single values for months (e.g. `JAN`, `DEC`)
|
63
|
+
1. Alternative single values for weekdays (e.g. `MON`, `SUN`)
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
To work on Cronut:
|
68
|
+
|
69
|
+
1. Clone this repository
|
70
|
+
1. Run `bundle install`
|
71
|
+
1. Run the tests using `rake`
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|
76
|
+
|
77
|
+
## Contribution Guidelines
|
78
|
+
|
79
|
+
Please note that this project is released with a [Contributor Code of Conduct](http://contributor-covenant.org/version/1/4/). By participating in this project you agree to abide by its terms.
|
data/Rakefile
ADDED
data/bin/cronut
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cronut'
|
4
|
+
|
5
|
+
expression = ARGV[0]
|
6
|
+
|
7
|
+
unless expression
|
8
|
+
puts 'Usage: cronut <expression>'
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
puts Cronut::Expression.new(expression)
|
14
|
+
rescue ArgumentError => e
|
15
|
+
puts "Unable to parse '#{expression}': #{e.message}"
|
16
|
+
exit 1
|
17
|
+
end
|
data/cronut.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'cronut/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'cronut'
|
7
|
+
spec.version = Cronut::VERSION
|
8
|
+
spec.authors = ['Josh McMillan']
|
9
|
+
spec.email = ['josh@joshmcmillan.co.uk']
|
10
|
+
|
11
|
+
spec.summary = 'A simple cron parser'
|
12
|
+
spec.homepage = 'https://github.com/mcmillan/cronut'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = ['cronut']
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
data/lib/cronut.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'cronut/version'
|
2
|
+
|
3
|
+
require 'cronut/parser'
|
4
|
+
require 'cronut/parser/base'
|
5
|
+
require 'cronut/parser/any'
|
6
|
+
require 'cronut/parser/list'
|
7
|
+
require 'cronut/parser/range'
|
8
|
+
require 'cronut/parser/step'
|
9
|
+
require 'cronut/parser/exact'
|
10
|
+
|
11
|
+
require 'cronut/segment/base'
|
12
|
+
require 'cronut/segment/minute'
|
13
|
+
require 'cronut/segment/hour'
|
14
|
+
require 'cronut/segment/day'
|
15
|
+
require 'cronut/segment/month'
|
16
|
+
require 'cronut/segment/weekday'
|
17
|
+
|
18
|
+
require 'cronut/expression'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Cronut
|
2
|
+
class Expression
|
3
|
+
attr_reader :expression, :minute, :hour, :day, :month, :weekday, :command
|
4
|
+
|
5
|
+
def initialize(expression)
|
6
|
+
@expression = expression
|
7
|
+
parse
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
<<~EOF
|
12
|
+
minute #{minute}
|
13
|
+
hour #{hour}
|
14
|
+
day of month #{day}
|
15
|
+
month #{month}
|
16
|
+
day of week #{weekday}
|
17
|
+
command #{command}
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse
|
24
|
+
segments = expression.strip.split(/\s+/, 6)
|
25
|
+
|
26
|
+
raise ArgumentError, 'Must be 6 segments' unless segments.count == 6
|
27
|
+
|
28
|
+
@minute = Cronut::Segment::Minute.new(segments[0])
|
29
|
+
@hour = Cronut::Segment::Hour.new(segments[1])
|
30
|
+
@day = Cronut::Segment::Day.new(segments[2])
|
31
|
+
@month = Cronut::Segment::Month.new(segments[3])
|
32
|
+
@weekday = Cronut::Segment::Weekday.new(segments[4])
|
33
|
+
@command = segments[5]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Cronut
|
2
|
+
module Parser
|
3
|
+
def self.for(segment:, maximum:, minimum:)
|
4
|
+
case segment
|
5
|
+
when '*'
|
6
|
+
klass = Cronut::Parser::Any
|
7
|
+
when /,/
|
8
|
+
klass = Cronut::Parser::List
|
9
|
+
when /[0-9]+-[0-9]+/
|
10
|
+
klass = Cronut::Parser::Range
|
11
|
+
when /\//
|
12
|
+
klass = Cronut::Parser::Step
|
13
|
+
when /^[0-9]+$/
|
14
|
+
klass = Cronut::Parser::Exact
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Invalid segment: #{segment}"
|
17
|
+
end
|
18
|
+
|
19
|
+
klass.new(segment: segment, maximum: maximum, minimum: minimum)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Cronut
|
2
|
+
module Parser
|
3
|
+
class Base
|
4
|
+
attr_reader :segment, :minimum, :maximum, :possibilities
|
5
|
+
|
6
|
+
def initialize(segment:, minimum:, maximum:)
|
7
|
+
@segment = segment
|
8
|
+
@minimum = minimum
|
9
|
+
@maximum = maximum
|
10
|
+
|
11
|
+
@possibilities = generate_possibilities
|
12
|
+
validate_possibilities!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def generate_possibilities
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate_possibilities!
|
22
|
+
@possibilities.each do |possibility|
|
23
|
+
next if (minimum..maximum).cover?(possibility)
|
24
|
+
raise ArgumentError, 'Possibilities exceed permitted range'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def safely_convert_to_integer(n)
|
29
|
+
Integer(n)
|
30
|
+
rescue ArgumentError
|
31
|
+
raise ArgumentError, "Non-numeric value supplied: #{n}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Cronut
|
2
|
+
module Parser
|
3
|
+
class Step < Base
|
4
|
+
private
|
5
|
+
|
6
|
+
def generate_possibilities
|
7
|
+
start, step = segment.split('/', 2)
|
8
|
+
|
9
|
+
start = minimum if start == '*'
|
10
|
+
|
11
|
+
start = safely_convert_to_integer(start)
|
12
|
+
step = safely_convert_to_integer(step)
|
13
|
+
|
14
|
+
raise ArgumentError, 'start exceeds maximum' if start > maximum
|
15
|
+
raise ArgumentError, 'step exceeds maximum' if step > maximum
|
16
|
+
|
17
|
+
start.upto(maximum).each_slice(step).map(&:first)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Cronut
|
2
|
+
module Segment
|
3
|
+
class Base
|
4
|
+
attr_reader :possibilities
|
5
|
+
|
6
|
+
def initialize(segment)
|
7
|
+
parser = Cronut::Parser.for(
|
8
|
+
segment: segment,
|
9
|
+
minimum: minimum,
|
10
|
+
maximum: maximum
|
11
|
+
)
|
12
|
+
@possibilities = parser.possibilities
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
possibilities.join(' ')
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def minimum
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def maximum
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cronut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh McMillan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- josh@joshmcmillan.co.uk
|
58
|
+
executables:
|
59
|
+
- cronut
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.md
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/cronut
|
71
|
+
- cronut.gemspec
|
72
|
+
- lib/cronut.rb
|
73
|
+
- lib/cronut/expression.rb
|
74
|
+
- lib/cronut/parser.rb
|
75
|
+
- lib/cronut/parser/any.rb
|
76
|
+
- lib/cronut/parser/base.rb
|
77
|
+
- lib/cronut/parser/exact.rb
|
78
|
+
- lib/cronut/parser/list.rb
|
79
|
+
- lib/cronut/parser/range.rb
|
80
|
+
- lib/cronut/parser/step.rb
|
81
|
+
- lib/cronut/segment/base.rb
|
82
|
+
- lib/cronut/segment/day.rb
|
83
|
+
- lib/cronut/segment/hour.rb
|
84
|
+
- lib/cronut/segment/minute.rb
|
85
|
+
- lib/cronut/segment/month.rb
|
86
|
+
- lib/cronut/segment/weekday.rb
|
87
|
+
- lib/cronut/version.rb
|
88
|
+
homepage: https://github.com/mcmillan/cronut
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A simple cron parser
|
112
|
+
test_files: []
|