parse-cron-ext 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/cron_parse.rb +112 -0
- data/lib/parse-cron-ext/version.rb +7 -0
- data/parse-cron-ext.gemspec +28 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92c12e5f584a2ced4ef9d81a2c58b29ce29e9b72106ce2320253de25a08b5838
|
4
|
+
data.tar.gz: 8e6a58e1ada748bf525f2dbc1b5a9b770aa25b35f66f34991d1918418c6980b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f49102492f26865f3326575cc6c5e55009a49489807888ed7317b26e9b827d9924ccf0f5a3d6770d4195f6ad9d19d8c2e8ef0c3d39895c101f958cb55b5e80c
|
7
|
+
data.tar.gz: ae7aa92ddb3aff49f488329aa44f291fcf79eb4b6b344ea20f2724311e21ab096a795e6109b59d9ebb60ec81ae0ab26c3a02490c01191c461c3d7af7b363b8c1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sh07e1916@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
parse-cron-ext (0.1.0)
|
5
|
+
parse-cron (>= 0.1.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
method_source (1.0.0)
|
13
|
+
parse-cron (0.1.4)
|
14
|
+
pry (0.14.1)
|
15
|
+
coderay (~> 1.1)
|
16
|
+
method_source (~> 1.0)
|
17
|
+
rake (12.3.3)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.2)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.3)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.3)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
parse-cron-ext!
|
37
|
+
pry
|
38
|
+
rake (~> 12.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 a5-stable
|
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,43 @@
|
|
1
|
+
# parse-cron-ext
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/parse/cron/ext`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'parse-cron-ext'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install parse-cron-ext
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/parse-cron-ext. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/parse-cron-ext/blob/master/CODE_OF_CONDUCT.md).
|
35
|
+
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Parse::Cron::Ext project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/parse-cron-ext/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "parse/cron/ext"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/cron_parse.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'date'
|
3
|
+
require 'parse-cron'
|
4
|
+
|
5
|
+
class CronParser
|
6
|
+
SUBELEMENT_REGEX = %r{^(\d+|l)((-(\d+)(/(\d+))?)?|#(\d+))$}
|
7
|
+
|
8
|
+
def parse_element(elem, allowed_range, time_specs_key=nil)
|
9
|
+
values = elem.split(',').map do |subel|
|
10
|
+
if subel =~ /^\*/
|
11
|
+
step = subel.length > 1 ? subel[2..-1].to_i : 1
|
12
|
+
stepped_range(allowed_range, step)
|
13
|
+
else
|
14
|
+
if SUBELEMENT_REGEX === subel
|
15
|
+
if $6 # with range
|
16
|
+
stepped_range($1.to_i..$4.to_i, $6.to_i)
|
17
|
+
elsif $4 # range without step
|
18
|
+
stepped_range($1.to_i..$4.to_i, 1)
|
19
|
+
elsif $1 == "l" && time_specs_key == :dom
|
20
|
+
[$1]
|
21
|
+
else # just a numeric
|
22
|
+
@dow_offset = $7.to_i if $7
|
23
|
+
[$1.to_i]
|
24
|
+
end
|
25
|
+
else
|
26
|
+
raise ArgumentError, "Bad Vixie-style specification #{subel}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end.flatten
|
30
|
+
|
31
|
+
values = values.sort if time_specs_key.nil?
|
32
|
+
[Set.new(values), values, elem]
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def recursive_calculate(meth,time,num)
|
38
|
+
array = [time]
|
39
|
+
num.-(1).times do |num|
|
40
|
+
array << self.send(meth, array.last)
|
41
|
+
end
|
42
|
+
array
|
43
|
+
end
|
44
|
+
|
45
|
+
def nudge_date(t, dir = :next, can_nudge_month = true)
|
46
|
+
spec = interpolate_weekdays(t.year, t.month)[1]
|
47
|
+
spec = [spec[@dow_offset-1]] if @dow_offset
|
48
|
+
|
49
|
+
next_value = find_best_next(t.day, spec, dir)
|
50
|
+
t.day = next_value || (dir == :next ? spec.first : spec.last)
|
51
|
+
|
52
|
+
nudge_month(t, dir) if next_value.nil? && can_nudge_month
|
53
|
+
end
|
54
|
+
|
55
|
+
def nudge_month(t, dir = :next)
|
56
|
+
spec = time_specs[:month][1]
|
57
|
+
next_value = find_best_next(t.month, spec, dir)
|
58
|
+
t.month = next_value || (dir == :next ? spec.first : spec.last)
|
59
|
+
|
60
|
+
nudge_year(t, dir) if next_value.nil?
|
61
|
+
|
62
|
+
# we changed the month, so its likely that the date is incorrect now
|
63
|
+
valid_days = interpolate_weekdays(t.year, t.month)[1]
|
64
|
+
valid_days = [valid_days[@dow_offset-1]] if @dow_offset
|
65
|
+
t.day = dir == :next ? valid_days.first : valid_days.last
|
66
|
+
end
|
67
|
+
|
68
|
+
# returns a list of days which do both match time_spec[:dom] or time_spec[:dow]
|
69
|
+
def interpolate_weekdays(year, month)
|
70
|
+
@_interpolate_weekdays_cache ||= {}
|
71
|
+
@_interpolate_weekdays_cache["#{year}-#{month}"] ||= interpolate_weekdays_without_cache(year, month)
|
72
|
+
end
|
73
|
+
|
74
|
+
def interpolate_weekdays_without_cache(year, month)
|
75
|
+
t = Date.new(year, month, 1)
|
76
|
+
valid_mday, _, mday_field = time_specs[:dom]
|
77
|
+
valid_wday, _, wday_field = time_specs[:dow]
|
78
|
+
# Careful, if both DOW and DOM fields are non-wildcard,
|
79
|
+
# then we only need to match *one* for cron to run the job:
|
80
|
+
if not (mday_field == '*' and wday_field == '*')
|
81
|
+
valid_mday = [] if mday_field == '*'
|
82
|
+
valid_wday = [] if wday_field == '*'
|
83
|
+
end
|
84
|
+
# Careful: crontabs may use either 0 or 7 for Sunday:
|
85
|
+
valid_wday << 0 if valid_wday.include?(7)
|
86
|
+
|
87
|
+
# Now only handle "L" statement
|
88
|
+
valid_mday << (t.next_month - 1).day if valid_mday.include?("l")
|
89
|
+
|
90
|
+
result = []
|
91
|
+
while t.month == month
|
92
|
+
result << t.mday if valid_mday.include?(t.mday) || valid_wday.include?(t.wday)
|
93
|
+
t = t.succ
|
94
|
+
end
|
95
|
+
|
96
|
+
[Set.new(result), result]
|
97
|
+
end
|
98
|
+
|
99
|
+
def time_specs
|
100
|
+
@time_specs ||= begin
|
101
|
+
# tokens now contains the 5 fields
|
102
|
+
tokens = substitute_parse_symbols(@source).split(/\s+/)
|
103
|
+
{
|
104
|
+
:minute => parse_element(tokens[0], 0..59), #minute
|
105
|
+
:hour => parse_element(tokens[1], 0..23), #hour
|
106
|
+
:dom => parse_element(tokens[2], 1..31, :dom), #DOM
|
107
|
+
:month => parse_element(tokens[3], 1..12), #mon
|
108
|
+
:dow => parse_element(tokens[4], 0..6) #DOW
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/parse-cron-ext/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "parse-cron-ext"
|
5
|
+
spec.version = Parse::Cron::Ext::VERSION
|
6
|
+
spec.authors = ["a5-stable"]
|
7
|
+
spec.email = ["sh07e1916@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{}
|
10
|
+
spec.description = %q{}
|
11
|
+
spec.homepage = "https://yahoo.co.jp"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = "https://github.com/a5-stable/parse-cron-ext"
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/a5-stable/parse-cron-ext"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/a5-stable/parse-cron-ext"
|
18
|
+
spec.add_dependency 'parse-cron', '>= 0.1.4'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parse-cron-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- a5-stable
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: parse-cron
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.4
|
27
|
+
description: ''
|
28
|
+
email:
|
29
|
+
- sh07e1916@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- lib/cron_parse.rb
|
46
|
+
- lib/parse-cron-ext/version.rb
|
47
|
+
- parse-cron-ext.gemspec
|
48
|
+
homepage: https://yahoo.co.jp
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
homepage_uri: https://github.com/a5-stable/parse-cron-ext
|
53
|
+
source_code_uri: https://github.com/a5-stable/parse-cron-ext
|
54
|
+
changelog_uri: https://github.com/a5-stable/parse-cron-ext
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.3.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.3.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: ''
|
74
|
+
test_files: []
|