repeatable 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +77 -0
  3. data/CHANGELOG.md +27 -1
  4. data/CODE_OF_CONDUCT.md +128 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +89 -24
  7. data/README.md +44 -8
  8. data/Rakefile +5 -1
  9. data/bin/tapioca +29 -0
  10. data/lib/repeatable/conversions.rb +7 -2
  11. data/lib/repeatable/expression/base.rb +27 -11
  12. data/lib/repeatable/expression/biweekly.rb +15 -6
  13. data/lib/repeatable/expression/date.rb +11 -6
  14. data/lib/repeatable/expression/day_in_month.rb +5 -0
  15. data/lib/repeatable/expression/difference.rb +15 -5
  16. data/lib/repeatable/expression/exact_date.rb +6 -1
  17. data/lib/repeatable/expression/intersection.rb +8 -2
  18. data/lib/repeatable/expression/range_in_year.rb +34 -9
  19. data/lib/repeatable/expression/set.rb +17 -6
  20. data/lib/repeatable/expression/union.rb +7 -1
  21. data/lib/repeatable/expression/weekday.rb +5 -0
  22. data/lib/repeatable/expression/weekday_in_month.rb +15 -1
  23. data/lib/repeatable/expression.rb +2 -0
  24. data/lib/repeatable/last_date_of_month.rb +5 -0
  25. data/lib/repeatable/parse_error.rb +2 -0
  26. data/lib/repeatable/parser.rb +8 -1
  27. data/lib/repeatable/schedule.rb +24 -4
  28. data/lib/repeatable/types.rb +7 -0
  29. data/lib/repeatable/version.rb +3 -1
  30. data/lib/repeatable.rb +5 -0
  31. data/rbi/repeatable.rbi +316 -0
  32. data/repeatable.gemspec +3 -0
  33. data/sorbet/config +4 -0
  34. data/sorbet/rbi/annotations/.gitattributes +1 -0
  35. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  36. data/sorbet/rbi/gems/.gitattributes +1 -0
  37. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  38. data/sorbet/rbi/gems/coderay@1.1.3.rbi +3426 -0
  39. data/sorbet/rbi/gems/commander@4.6.0.rbi +8 -0
  40. data/sorbet/rbi/gems/diff-lcs@1.4.4.rbi +1082 -0
  41. data/sorbet/rbi/gems/docile@1.4.0.rbi +376 -0
  42. data/sorbet/rbi/gems/erubi@1.12.0.rbi +145 -0
  43. data/sorbet/rbi/gems/highline@2.0.3.rbi +8 -0
  44. data/sorbet/rbi/gems/json@2.7.2.rbi +1561 -0
  45. data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +14237 -0
  46. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +239 -0
  47. data/sorbet/rbi/gems/method_source@1.0.0.rbi +272 -0
  48. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  49. data/sorbet/rbi/gems/parallel@1.24.0.rbi +280 -0
  50. data/sorbet/rbi/gems/parlour@8.1.0.rbi +3053 -0
  51. data/sorbet/rbi/gems/parser@3.3.1.0.rbi +7320 -0
  52. data/sorbet/rbi/gems/prism@0.28.0.rbi +37903 -0
  53. data/sorbet/rbi/gems/pry@0.14.0.rbi +10072 -0
  54. data/sorbet/rbi/gems/racc@1.7.3.rbi +161 -0
  55. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +402 -0
  56. data/sorbet/rbi/gems/rake@13.0.3.rbi +3024 -0
  57. data/sorbet/rbi/gems/rbi@0.1.13.rbi +3071 -0
  58. data/sorbet/rbi/gems/regexp_parser@2.9.0.rbi +3771 -0
  59. data/sorbet/rbi/gems/rexml@3.2.6.rbi +4781 -0
  60. data/sorbet/rbi/gems/rspec-core@3.10.1.rbi +10837 -0
  61. data/sorbet/rbi/gems/rspec-expectations@3.10.1.rbi +7930 -0
  62. data/sorbet/rbi/gems/rspec-mocks@3.10.2.rbi +5247 -0
  63. data/sorbet/rbi/gems/rspec-support@3.10.2.rbi +1594 -0
  64. data/sorbet/rbi/gems/rspec@3.10.0.rbi +76 -0
  65. data/sorbet/rbi/gems/rubocop-ast@1.31.3.rbi +7014 -0
  66. data/sorbet/rbi/gems/rubocop-performance@1.20.2.rbi +8 -0
  67. data/sorbet/rbi/gems/rubocop@1.62.1.rbi +57542 -0
  68. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1317 -0
  69. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +216 -0
  70. data/sorbet/rbi/gems/simplecov@0.21.2.rbi +2135 -0
  71. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +8 -0
  72. data/sorbet/rbi/gems/spoom@1.3.2.rbi +4420 -0
  73. data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +8 -0
  74. data/sorbet/rbi/gems/standard-performance@1.3.1.rbi +8 -0
  75. data/sorbet/rbi/gems/standard@1.35.1.rbi +850 -0
  76. data/sorbet/rbi/gems/tapioca@0.13.3.rbi +3527 -0
  77. data/sorbet/rbi/gems/thor@1.3.1.rbi +4351 -0
  78. data/sorbet/rbi/gems/unicode-display_width@2.5.0.rbi +65 -0
  79. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +428 -0
  80. data/sorbet/rbi/gems/yard@0.9.36.rbi +18220 -0
  81. data/sorbet/tapioca/config.yml +13 -0
  82. data/sorbet/tapioca/require.rb +4 -0
  83. metadata +75 -6
  84. data/.travis.yml +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f6976240c976a027e08e04dc46dff2a7a420894f089ae7fa8c9fded126bafc6
4
- data.tar.gz: 4e0e0e4d45d72b543549904a9a6f4b041430b9808075ccb64a81583366a4e414
3
+ metadata.gz: 4b0b02925c282f8d672cff3b6c4683939d5c734f0e682b1a4ea8e5feb931a765
4
+ data.tar.gz: 4446324d2c752fd1f33ef15545f58de7680ae48743d4f9343062c9151569abbc
5
5
  SHA512:
6
- metadata.gz: 2698038cb582f612642c1b2f9c595e3830ff42556fb89eef56d4bbf5e3c34396d318175699ecb74a2c589aefe861cc5c7e17a6bde0b4950b6939421fedcb1260
7
- data.tar.gz: 6a98285ed9058b186651055e5afecae2b2abcb64ca0dbc488b92b76ff6a20da02d4ab1d96f204bd864b210a5d183fdff34db31b82d4b06595e0b7c16f2dc3dcf
6
+ metadata.gz: daa01ada7a7d30730829bcf01ba053c4dd325923a574cf78af0b8a5531b543752392f239d96f3658f8a2045313e5df50cca92c75d91fc29aa5484e7e16224ccd
7
+ data.tar.gz: '080a67d068f2b4663d0ed106d78371f10c47b576b65a52fb5d43fc19b78b0fc1a3449cb288899b089c1b26b77a039cf29cb9fc5b0e828fdd1b7a9a3154aecebb'
@@ -0,0 +1,77 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - 'ml/**'
8
+ pull_request:
9
+ branches:
10
+ - main
11
+
12
+ jobs:
13
+ RSpec:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby-version:
19
+ - '2.5' # deprecated
20
+ - '2.6'
21
+ - '2.7'
22
+ - '3.0'
23
+ - '3.1'
24
+ include:
25
+ - ruby-version: '3.1'
26
+ coverage: 'true'
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - name: Remove Gemfile.lock for older Ruby versions
30
+ if: ${{ fromJSON(matrix.ruby-version) < 3.1 }}
31
+ run: rm Gemfile.lock
32
+ - name: Set up Ruby ${{ matrix.ruby-version }}
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true
37
+ - uses: amancevice/setup-code-climate@v0
38
+ name: CodeClimate setup
39
+ if: ${{ matrix.coverage == 'true' }}
40
+ with:
41
+ cc_test_reporter_id: ${{ secrets.CC_TEST_REPORTER_ID }}
42
+ - name: CodeClimate before-build
43
+ run: cc-test-reporter before-build
44
+ if: ${{ matrix.coverage == 'true' }}
45
+ continue-on-error: true
46
+ - name: Run tests
47
+ env:
48
+ COVERAGE: ${{ matrix.coverage }}
49
+ run: bundle exec rake spec
50
+ - name: CodeClimate after-build
51
+ run: cc-test-reporter after-build
52
+ if: ${{ matrix.coverage == 'true' }}
53
+ continue-on-error: true
54
+ Standard:
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - uses: actions/checkout@v2
58
+ - name: Set up Ruby
59
+ uses: ruby/setup-ruby@v1
60
+ with:
61
+ ruby-version: '3.1'
62
+ bundler-cache: true
63
+ - name: Run Standard
64
+ run: bundle exec rake standard
65
+ Sorbet:
66
+ runs-on: ubuntu-latest
67
+ steps:
68
+ - uses: actions/checkout@v2
69
+ - name: Set up Ruby
70
+ uses: ruby/setup-ruby@v1
71
+ with:
72
+ ruby-version: '3.1'
73
+ bundler-cache: true
74
+ - name: Check gem RBI files
75
+ run: bin/tapioca gems --verify
76
+ - name: Run Sorbet
77
+ run: bundle exec rake sorbet
data/CHANGELOG.md CHANGED
@@ -2,7 +2,33 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
- [Commits](https://github.com/molawson/repeatable/compare/v1.0.0...main)
5
+ [Commits](https://github.com/molawson/repeatable/compare/v1.2.0...main)
6
+
7
+ ### 1.2.0 (2024-04-25)
8
+
9
+ Changes:
10
+
11
+ * Support pattern matching for `Expression` and `Schedule`
12
+ * Support more recent versions of sorbet
13
+
14
+ [Commits](https://github.com/molawson/repeatable/compare/v1.1.0...v1.2.0)
15
+
16
+ ### 1.1.0 (2022-02-25)
17
+
18
+ Changes:
19
+
20
+ * Add [sorbet](https://sorbet.org) for type checking
21
+
22
+ Bug Fixes:
23
+
24
+ * Ensure `first_occurrence` is never part of `#to_h` output for `Expression::Biweekly`
25
+
26
+ Chores:
27
+
28
+ * Add support for Ruby 3.1
29
+ * Deprecate support for Ruby 2.5
30
+
31
+ [Commits](https://github.com/molawson/repeatable/compare/v1.0.0...v1.1.0)
6
32
 
7
33
  ### 1.0.0 (2021-03-25)
8
34
 
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ mo@molawson.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
data/Gemfile CHANGED
@@ -3,9 +3,12 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in repeatable.gemspec
4
4
  gemspec
5
5
 
6
+ gem "parlour"
6
7
  gem "pry", "~> 0.13"
7
8
  gem "rake", ">= 12.3.3"
9
+ gem "sorbet-static-and-runtime"
8
10
  gem "standard", "~> 1.0"
11
+ gem "tapioca"
9
12
 
10
13
  group :test do
11
14
  gem "rspec", "~> 3.0"
data/Gemfile.lock CHANGED
@@ -1,26 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- repeatable (1.0.0)
4
+ repeatable (1.2.0)
5
+ sorbet-runtime
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  ast (2.4.2)
10
11
  coderay (1.1.3)
12
+ commander (4.6.0)
13
+ highline (~> 2.0.0)
11
14
  diff-lcs (1.4.4)
12
- docile (1.3.5)
15
+ docile (1.4.0)
16
+ erubi (1.12.0)
17
+ highline (2.0.3)
18
+ json (2.7.2)
19
+ language_server-protocol (3.17.0.3)
20
+ lint_roller (1.1.0)
13
21
  method_source (1.0.0)
14
- parallel (1.20.1)
15
- parser (3.0.0.0)
22
+ netrc (0.11.0)
23
+ parallel (1.24.0)
24
+ parlour (8.1.0)
25
+ commander (~> 4.5)
26
+ parser
27
+ rainbow (~> 3.0)
28
+ sorbet-runtime (>= 0.5)
29
+ parser (3.3.1.0)
16
30
  ast (~> 2.4.1)
31
+ racc
32
+ prism (0.28.0)
17
33
  pry (0.14.0)
18
34
  coderay (~> 1.1)
19
35
  method_source (~> 1.0)
20
- rainbow (3.0.0)
36
+ racc (1.7.3)
37
+ rainbow (3.1.1)
21
38
  rake (13.0.3)
22
- regexp_parser (2.1.1)
23
- rexml (3.2.4)
39
+ rbi (0.1.13)
40
+ prism (>= 0.18.0, < 1.0.0)
41
+ sorbet-runtime (>= 0.5.9204)
42
+ regexp_parser (2.9.0)
43
+ rexml (3.2.6)
24
44
  rspec (3.10.0)
25
45
  rspec-core (~> 3.10.0)
26
46
  rspec-expectations (~> 3.10.0)
@@ -34,43 +54,88 @@ GEM
34
54
  diff-lcs (>= 1.2.0, < 2.0)
35
55
  rspec-support (~> 3.10.0)
36
56
  rspec-support (3.10.2)
37
- rubocop (1.11.0)
57
+ rubocop (1.62.1)
58
+ json (~> 2.3)
59
+ language_server-protocol (>= 3.17.0)
38
60
  parallel (~> 1.10)
39
- parser (>= 3.0.0.0)
61
+ parser (>= 3.3.0.2)
40
62
  rainbow (>= 2.2.2, < 4.0)
41
63
  regexp_parser (>= 1.8, < 3.0)
42
- rexml
43
- rubocop-ast (>= 1.2.0, < 2.0)
64
+ rexml (>= 3.2.5, < 4.0)
65
+ rubocop-ast (>= 1.31.1, < 2.0)
44
66
  ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 3.0)
46
- rubocop-ast (1.4.1)
47
- parser (>= 2.7.1.5)
48
- rubocop-performance (1.10.1)
49
- rubocop (>= 0.90.0, < 2.0)
50
- rubocop-ast (>= 0.4.0)
51
- ruby-progressbar (1.11.0)
67
+ unicode-display_width (>= 2.4.0, < 3.0)
68
+ rubocop-ast (1.31.3)
69
+ parser (>= 3.3.1.0)
70
+ rubocop-performance (1.20.2)
71
+ rubocop (>= 1.48.1, < 2.0)
72
+ rubocop-ast (>= 1.30.0, < 2.0)
73
+ ruby-progressbar (1.13.0)
52
74
  simplecov (0.21.2)
53
75
  docile (~> 1.1)
54
76
  simplecov-html (~> 0.11)
55
77
  simplecov_json_formatter (~> 0.1)
56
78
  simplecov-html (0.12.3)
57
- simplecov_json_formatter (0.1.2)
58
- standard (1.0.4)
59
- rubocop (= 1.11.0)
60
- rubocop-performance (= 1.10.1)
61
- unicode-display_width (2.0.0)
79
+ simplecov_json_formatter (0.1.4)
80
+ sorbet (0.5.11370)
81
+ sorbet-static (= 0.5.11370)
82
+ sorbet-runtime (0.5.11370)
83
+ sorbet-static (0.5.11370-aarch64-linux)
84
+ sorbet-static (0.5.11370-universal-darwin)
85
+ sorbet-static (0.5.11370-x86_64-linux)
86
+ sorbet-static-and-runtime (0.5.11370)
87
+ sorbet (= 0.5.11370)
88
+ sorbet-runtime (= 0.5.11370)
89
+ spoom (1.3.2)
90
+ erubi (>= 1.10.0)
91
+ prism (>= 0.19.0)
92
+ sorbet-static-and-runtime (>= 0.5.10187)
93
+ thor (>= 0.19.2)
94
+ standard (1.35.1)
95
+ language_server-protocol (~> 3.17.0.2)
96
+ lint_roller (~> 1.0)
97
+ rubocop (~> 1.62.0)
98
+ standard-custom (~> 1.0.0)
99
+ standard-performance (~> 1.3)
100
+ standard-custom (1.0.2)
101
+ lint_roller (~> 1.0)
102
+ rubocop (~> 1.50)
103
+ standard-performance (1.3.1)
104
+ lint_roller (~> 1.1)
105
+ rubocop-performance (~> 1.20.2)
106
+ tapioca (0.13.3)
107
+ bundler (>= 2.2.25)
108
+ netrc (>= 0.11.0)
109
+ parallel (>= 1.21.0)
110
+ rbi (>= 0.1.4, < 0.2)
111
+ sorbet-static-and-runtime (>= 0.5.11087)
112
+ spoom (>= 1.2.0)
113
+ thor (>= 1.2.0)
114
+ yard-sorbet
115
+ thor (1.3.1)
116
+ unicode-display_width (2.5.0)
117
+ yard (0.9.36)
118
+ yard-sorbet (0.8.1)
119
+ sorbet-runtime (>= 0.5)
120
+ yard (>= 0.9)
62
121
 
63
122
  PLATFORMS
123
+ arm64-darwin-21
124
+ arm64-darwin-23
125
+ linux
64
126
  x86_64-darwin-19
65
127
  x86_64-linux
66
128
 
67
129
  DEPENDENCIES
130
+ parlour
68
131
  pry (~> 0.13)
69
132
  rake (>= 12.3.3)
70
133
  repeatable!
71
134
  rspec (~> 3.0)
72
135
  simplecov (~> 0.18)
136
+ sorbet-static-and-runtime
73
137
  standard (~> 1.0)
138
+ tapioca
74
139
 
75
140
  BUNDLED WITH
76
- 2.2.14
141
+ 2.3.6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Repeatable
2
2
 
3
- [![Build Status](https://travis-ci.org/molawson/repeatable.svg?branch=main)](https://travis-ci.org/molawson/repeatable)
3
+ [![CI](https://github.com/molawson/repeatable/actions/workflows/ci.yml/badge.svg)](https://github.com/molawson/repeatable/actions/workflows/ci.yml)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/73707efd5eeffd364c0d/maintainability)](https://codeclimate.com/github/molawson/repeatable/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/73707efd5eeffd364c0d/test_coverage)](https://codeclimate.com/github/molawson/repeatable/test_coverage)
6
6
 
@@ -22,10 +22,6 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install repeatable
24
24
 
25
- ## Requirements
26
-
27
- Because this gem relies heavily on required keyword arguments, especially to make dumping and parsing of schedules simpler, this code will only work on **Ruby 2.2** and higher.
28
-
29
25
  ## Usage
30
26
 
31
27
  ### Building a Schedule
@@ -98,8 +94,8 @@ Repeatable::Expression::WeekdayInMonth.new(weekday: 1, count: 3)
98
94
  Repeatable::Expression::WeekdayInMonth.new(weekday: 4, count: -1)
99
95
 
100
96
  # Every other Monday, starting from December 1, 2015
101
- { biweekly: { weekday: 1, start_date: '2015-12-01' } }
102
- Repeatable::Expression::Biweekly.new(weekday: 1, start_date: Date.new(2015, 12, 1))
97
+ { biweekly: { weekday: 1, start_after: '2015-12-01' } }
98
+ Repeatable::Expression::Biweekly.new(weekday: 1, start_after: Date.new(2015, 12, 1))
103
99
 
104
100
  # The 13th of every month
105
101
  { day_in_month: { day: 13 } }
@@ -163,6 +159,21 @@ schedule.to_h
163
159
  # can be used to recreate an identical Schedule object at a later time
164
160
  ```
165
161
 
162
+ #### Pattern Matching
163
+
164
+ Both `Repeatable::Schedule` and all `Repeatable::Expression` classes support Ruby 2.7+ [pattern matching][ruby-pattern-matching] which is particularly useful for parsing or presenting an existing schedule.
165
+
166
+ ```ruby
167
+ case schedule
168
+ in weekday: { weekday: }
169
+ "Weekly on #{Date::DAYNAMES[weekday]}"
170
+ in day_in_month: { day: }
171
+ "Every month on the #{day.ordinalize}"
172
+ in weekday_in_month: { weekday:, count: }
173
+ "Every month on the #{count.ordinalize} #{Date::DAYNAMES[weekday]}"
174
+ end
175
+ ```
176
+
166
177
  #### Equivalence
167
178
 
168
179
  Both `Repeatable::Schedule` and all `Repeatable::Expression` classes have equivalence `#==` defined according to what's appropriate for each class, so regardless of the order of arguments passed to each, you can tell whether one object is equivalent to the other in terms of whether or not, when asked the same questions, you'd receive the same results from each.
@@ -186,16 +197,41 @@ Repeatable::Schedule.new(union) == Repeatable::Schedule.new(another_union)
186
197
 
187
198
  ```
188
199
 
200
+ ## Ruby version support
201
+
202
+ Currently tested and supported:
203
+ - 2.6
204
+ - 2.7
205
+ - 3.0
206
+ - 3.1
207
+
208
+ Deprecated (currently tested but has reached EOL and will be unsupported in the next major version):
209
+ - 2.5
210
+
211
+ The supported versions will roughly track with versions that are currently maintained by the Ruby core team.
212
+
189
213
  ## Development
190
214
 
191
215
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
192
216
 
193
- 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
217
+ You can run the tests with `bundle exec rake`.
194
218
 
195
219
  ## Contributing
196
220
 
221
+ Bug reports and pull requests are welcome on GitHub at https://github.com/molawson/repeatable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
222
+
197
223
  1. Fork it ( https://github.com/molawson/repeatable/fork )
198
224
  2. Create your feature branch (`git checkout -b my-new-feature`)
199
225
  3. Commit your changes (`git commit -am 'Add some feature'`)
200
226
  4. Push to the branch (`git push origin my-new-feature`)
201
227
  5. Create a new Pull Request
228
+
229
+ ## License
230
+
231
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
232
+
233
+ ## Code of Conduct
234
+
235
+ Everyone interacting in the Repeatable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/molawson/repeatable/blob/main/CODE_OF_CONDUCT.md).
236
+
237
+ [ruby-pattern-matching]: https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html
data/Rakefile CHANGED
@@ -5,4 +5,8 @@ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  require "standard/rake"
7
7
 
8
- task default: %i[spec standard]
8
+ task :sorbet do
9
+ sh %(bundle exec srb tc)
10
+ end
11
+
12
+ task default: %i[spec sorbet standard]
data/bin/tapioca ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'tapioca' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("tapioca", "tapioca")
@@ -1,16 +1,21 @@
1
+ # typed: strict
2
+
1
3
  module Repeatable
2
4
  module Conversions
5
+ extend T::Sig
6
+
3
7
  module_function
4
8
 
9
+ sig { params(arg: Object).returns(::Date) }
5
10
  def Date(arg)
6
11
  case arg
7
12
  when Date, Time
8
13
  arg.to_date
9
14
  else
10
- Date.parse(arg)
15
+ Date.parse(T.let(arg, T.untyped))
11
16
  end
12
17
  rescue ArgumentError
13
- raise TypeError, "Cannot convert #{arg.inspect} to Date"
18
+ Kernel.raise TypeError, "Cannot convert #{arg.inspect} to Date"
14
19
  end
15
20
  end
16
21
  end
@@ -1,6 +1,14 @@
1
+ # typed: strict
2
+
1
3
  module Repeatable
2
4
  module Expression
3
5
  class Base
6
+ extend T::Sig
7
+ extend T::Helpers
8
+
9
+ abstract!
10
+
11
+ sig { params(other: Object).returns(T::Boolean) }
4
12
  def self.===(other)
5
13
  case other
6
14
  when Class
@@ -10,31 +18,34 @@ module Repeatable
10
18
  end
11
19
  end
12
20
 
13
- def include?(_date)
14
- fail(
15
- NotImplementedError,
16
- "Don't use Expression::Base directly. Subclasses must implement `#include?`"
17
- )
21
+ sig { abstract.params(date: ::Date).returns(T::Boolean) }
22
+ def include?(date)
18
23
  end
19
24
 
25
+ sig { returns(T::Hash[Symbol, T.any(Types::SymbolHash, T::Array[Types::SymbolHash])]) }
20
26
  def to_h
21
- fail(
22
- NotImplementedError,
23
- "Don't use Expression::Base directly. Subclasses must implement `#to_h`"
24
- )
27
+ {hash_key => hash_value}
25
28
  end
26
29
 
30
+ sig { params(_keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.any(Types::SymbolHash, T::Array[Types::SymbolHash])]) }
31
+ def deconstruct_keys(_keys)
32
+ to_h
33
+ end
34
+
35
+ sig { params(other: Expression::Base).returns(Expression::Union) }
27
36
  def union(other)
28
37
  Union.new(self, other)
29
38
  end
30
39
  alias_method :+, :union
31
40
  alias_method :|, :union
32
41
 
42
+ sig { params(other: Expression::Base).returns(Expression::Intersection) }
33
43
  def intersection(other)
34
44
  Intersection.new(self, other)
35
45
  end
36
46
  alias_method :&, :intersection
37
47
 
48
+ sig { params(other: T.untyped).returns(Expression::Difference) }
38
49
  def difference(other)
39
50
  Difference.new(included: self, excluded: other)
40
51
  end
@@ -42,12 +53,17 @@ module Repeatable
42
53
 
43
54
  private
44
55
 
56
+ sig { returns(Symbol) }
45
57
  def hash_key
46
- self.class.name.split("::").last
47
- .gsub(/(?<!\b)[A-Z]/) { "_#{Regexp.last_match[0]}" }
58
+ T.must(T.must(self.class.name).split("::").last)
59
+ .gsub(/(?<!\b)[A-Z]/) { "_#{T.must(Regexp.last_match)[0]}" }
48
60
  .downcase
49
61
  .to_sym
50
62
  end
63
+
64
+ sig { abstract.returns(T.any(Types::SymbolHash, T::Array[Types::SymbolHash])) }
65
+ def hash_value
66
+ end
51
67
  end
52
68
  end
53
69
  end