philiprehberger-cron_parser 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +14 -0
- data/lib/philiprehberger/cron_parser/expression.rb +17 -3
- data/lib/philiprehberger/cron_parser/version.rb +1 -1
- data/lib/philiprehberger/cron_parser.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d11c034aa656522a0e2ca5e145ca68f974b1b0eb9aeafad15797ee5a53d859f1
|
|
4
|
+
data.tar.gz: 874e7abb865fa66511d7a407e7e0cc4ea0dfd8e8a637ff75225cffc9db5f0206
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8053224dd61f4defd352fbdf106351f995de7b16b6f10b610a40e99c47f577c0b27d241587aa74cd4299da2d7a4601c6879844eb63d68ce47dfcaa383ce5847
|
|
7
|
+
data.tar.gz: f830772d6a686fec8dcf8f857a68b4be1f162bf70f0ebde4146f7228b44f5aadc18dbe567ce8570fcd4d5c5fa3125ab2ef56313978cec0320caa5b7796d458b5
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Named cron aliases (`@hourly`, `@daily`, `@midnight`, `@weekly`, `@monthly`, `@yearly`, `@annually`) with case-insensitive matching
|
|
14
|
+
- `valid?` and `validate` now accept alias expressions
|
|
15
|
+
|
|
10
16
|
## [0.2.0] - 2026-04-03
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -69,6 +69,20 @@ Philiprehberger::CronParser.new('0 0 * * MON,WED,FRI') # specific days
|
|
|
69
69
|
Philiprehberger::CronParser.new('0 0 * * 1,WED,5') # mixed numeric and named
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
### Named Aliases
|
|
73
|
+
|
|
74
|
+
Standard crontab aliases are supported (case-insensitive):
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
Philiprehberger::CronParser.new('@hourly') # => 0 * * * *
|
|
78
|
+
Philiprehberger::CronParser.new('@daily') # => 0 0 * * *
|
|
79
|
+
Philiprehberger::CronParser.new('@midnight') # alias for @daily
|
|
80
|
+
Philiprehberger::CronParser.new('@weekly') # => 0 0 * * 0
|
|
81
|
+
Philiprehberger::CronParser.new('@monthly') # => 0 0 1 * *
|
|
82
|
+
Philiprehberger::CronParser.new('@yearly') # => 0 0 1 1 *
|
|
83
|
+
Philiprehberger::CronParser.new('@annually') # alias for @yearly
|
|
84
|
+
```
|
|
85
|
+
|
|
72
86
|
### Validation
|
|
73
87
|
|
|
74
88
|
```ruby
|
|
@@ -30,13 +30,27 @@ module Philiprehberger
|
|
|
30
30
|
weekday: 'day of week'
|
|
31
31
|
}.freeze
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
ALIASES = {
|
|
34
|
+
'@yearly' => '0 0 1 1 *',
|
|
35
|
+
'@annually' => '0 0 1 1 *',
|
|
36
|
+
'@monthly' => '0 0 1 * *',
|
|
37
|
+
'@weekly' => '0 0 * * 0',
|
|
38
|
+
'@daily' => '0 0 * * *',
|
|
39
|
+
'@midnight' => '0 0 * * *',
|
|
40
|
+
'@hourly' => '0 * * * *'
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
# @return [String] the original (post-alias expansion) expression
|
|
34
44
|
attr_reader :expression
|
|
35
45
|
|
|
36
|
-
# @param expr [String] a 5-field cron expression
|
|
46
|
+
# @param expr [String] a 5-field cron expression or named alias (e.g. "@daily")
|
|
37
47
|
# @raise [Error] if the expression is invalid
|
|
38
48
|
def initialize(expr)
|
|
39
|
-
|
|
49
|
+
stripped = expr.strip
|
|
50
|
+
stripped = ALIASES[stripped.downcase] if stripped.start_with?('@')
|
|
51
|
+
raise Error, "Unknown cron alias: #{expr.strip}" if stripped.nil?
|
|
52
|
+
|
|
53
|
+
@expression = stripped
|
|
40
54
|
parts = @expression.split(/\s+/)
|
|
41
55
|
raise Error, "Expected 5 fields, got #{parts.size}: #{@expression}" unless parts.size == 5
|
|
42
56
|
|
|
@@ -37,6 +37,12 @@ module Philiprehberger
|
|
|
37
37
|
def self.validate(expr)
|
|
38
38
|
errors = []
|
|
39
39
|
stripped = expr.strip
|
|
40
|
+
if stripped.start_with?('@')
|
|
41
|
+
alias_expanded = Expression::ALIASES[stripped.downcase]
|
|
42
|
+
return { valid: false, errors: ["Unknown cron alias: #{stripped}"] } if alias_expanded.nil?
|
|
43
|
+
|
|
44
|
+
stripped = alias_expanded
|
|
45
|
+
end
|
|
40
46
|
parts = stripped.split(/\s+/)
|
|
41
47
|
|
|
42
48
|
unless parts.size == 5
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-cron_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Parse standard 5-field cron expressions and calculate next/previous occurrences,
|
|
14
14
|
match times against patterns, and generate human-readable descriptions.
|