dry-matcher 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -5
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/ci.yml +52 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +56 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +101 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +3 -7
- data/Gemfile.devtools +14 -0
- data/LICENSE +20 -0
- data/README.md +18 -14
- data/Rakefile +1 -5
- data/docsite/source/class-enhancement.html.md +30 -0
- data/docsite/source/index.html.md +89 -0
- data/docsite/source/result-matcher.html.md +34 -0
- data/dry-matcher.gemspec +1 -0
- data/lib/dry/matcher.rb +3 -0
- data/lib/dry/matcher/version.rb +1 -1
- data/project.yml +2 -0
- metadata +32 -4
- data/.travis.yml +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38ace71dc19f0f1e34802f9f93e1810a4e458c8607052a018b42616f8d6aa632
|
4
|
+
data.tar.gz: 7aadbced0d50bb92e5876a7fcd491528144fd989ef92ddc773e3374b61b06797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a45230d9bce5beb800c465fe0f1a566cbe3b577094d8e030d0de0307bfe01b1cb889f798dd0d7a971277f5e652dab4550a3426966f6db99f33b98a34c9259ce7
|
7
|
+
data.tar.gz: 8093fa57b20b25fe05534b392c28aebb0acf9e1061f36d4446ac4cbbcf5e2a5a286071548e1a96b2cae0fb70020425292b8919e884b80bb19de66be7015bbf3d
|
data/.codeclimate.yml
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F41B Bug report"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
|
+
|
12
|
+
For more information see `CONTRIBUTING.md`.
|
13
|
+
|
14
|
+
**Describe the bug**
|
15
|
+
|
16
|
+
A clear and concise description of what the bug is.
|
17
|
+
|
18
|
+
**To Reproduce**
|
19
|
+
|
20
|
+
Provide detailed steps to reproduce, an executable script would be best.
|
21
|
+
|
22
|
+
**Expected behavior**
|
23
|
+
|
24
|
+
A clear and concise description of what you expected to happen.
|
25
|
+
|
26
|
+
**Your environment**
|
27
|
+
|
28
|
+
- Affects my production application: **YES/NO**
|
29
|
+
- Ruby version: ...
|
30
|
+
- OS: ...
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
name: "\U0001F6E0 Feature request"
|
3
|
+
about: See CONTRIBUTING.md for more information
|
4
|
+
title: ''
|
5
|
+
labels: feature
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
Summary of what the feature is supposed to do.
|
11
|
+
|
12
|
+
## Examples
|
13
|
+
|
14
|
+
Code examples showing how the feature could be used.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: ci
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
paths:
|
8
|
+
- .github/workflows/ci.yml
|
9
|
+
- lib/**
|
10
|
+
- spec/**
|
11
|
+
- Rakefile
|
12
|
+
- Gemfile
|
13
|
+
- Gemfile.devtools
|
14
|
+
- "*.gemspec"
|
15
|
+
- ".rubocop.yml"
|
16
|
+
pull_request:
|
17
|
+
branches:
|
18
|
+
- master
|
19
|
+
|
20
|
+
jobs:
|
21
|
+
tests:
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
fail-fast: false
|
25
|
+
matrix:
|
26
|
+
ruby:
|
27
|
+
- "2.7"
|
28
|
+
- "2.6"
|
29
|
+
- "2.5"
|
30
|
+
- "2.4"
|
31
|
+
- "jruby"
|
32
|
+
include:
|
33
|
+
- ruby: "2.6"
|
34
|
+
coverage: "true"
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v1
|
37
|
+
- name: Set up Ruby
|
38
|
+
uses: eregon/use-ruby-action@master
|
39
|
+
with:
|
40
|
+
ruby-version: ${{matrix.ruby}}
|
41
|
+
- name: Install latest bundler
|
42
|
+
run: |
|
43
|
+
gem install bundler
|
44
|
+
bundle config set without 'tools benchmarks docs'
|
45
|
+
- name: Bundle install
|
46
|
+
run: bundle install --jobs 4 --retry 3
|
47
|
+
- name: Run all tests
|
48
|
+
env:
|
49
|
+
COVERAGE: ${{matrix.coverage}}
|
50
|
+
CODACY_RUN_LOCAL: true
|
51
|
+
CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
|
52
|
+
run: bundle exec rake
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: docsite
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
paths:
|
8
|
+
- docsite/**
|
9
|
+
- .github/workflows/docsite.yml
|
10
|
+
branches:
|
11
|
+
- master
|
12
|
+
- release-**
|
13
|
+
tags:
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
update-docs:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v1
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: actions/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: "2.6.x"
|
24
|
+
- name: Install dependencies
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
+
- name: Symlink ossy
|
29
|
+
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
+
- name: Trigger dry-rb.org deploy
|
31
|
+
env:
|
32
|
+
GITHUB_LOGIN: dry-bot
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
+
run: bin/ossy github workflow dry-rb/dry-rb.org ci
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
name: sync_configs
|
4
|
+
|
5
|
+
on:
|
6
|
+
repository_dispatch:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
sync-configs:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: github.event.action == 'sync_configs'
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v1
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: eregon/use-ruby-action@master
|
16
|
+
with:
|
17
|
+
ruby-version: 2.6
|
18
|
+
- name: Install latest bundler
|
19
|
+
run: |
|
20
|
+
gem install bundler
|
21
|
+
bundle config set without 'tools benchmarks docs'
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install --jobs 4 --retry 3 --without tools test benchmarks docs
|
24
|
+
- name: Symlink ossy
|
25
|
+
run: ln -sf "$(bundle info ossy --path)/bin/ossy" bin/ossy
|
26
|
+
- name: Clone devtools
|
27
|
+
run: git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
28
|
+
- name: Compile file templates
|
29
|
+
env:
|
30
|
+
GITHUB_LOGIN: dry-bot
|
31
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
32
|
+
run: |
|
33
|
+
if [ -f "project.yml" ]; then
|
34
|
+
for t in `ls tmp/devtools/templates`
|
35
|
+
do
|
36
|
+
bin/ossy t c tmp/devtools/templates/$t $(basename $t .erb) project.yml
|
37
|
+
done
|
38
|
+
fi
|
39
|
+
- name: Update configuration files from devtools
|
40
|
+
run: |
|
41
|
+
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
42
|
+
rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
43
|
+
else
|
44
|
+
rsync -arv tmp/devtools/shared/ . ;
|
45
|
+
fi
|
46
|
+
- name: Commit changes
|
47
|
+
run: |
|
48
|
+
rm bin/ossy
|
49
|
+
git config --local user.email "dry-bot@dry-rb.org"
|
50
|
+
git config --local user.name "dry-bot"
|
51
|
+
git add -A
|
52
|
+
git commit -m "[devtools] sync configs" || echo "nothing changed"
|
53
|
+
- name: Push changes
|
54
|
+
uses: ad-m/github-push-action@master
|
55
|
+
with:
|
56
|
+
github_token: ${{ secrets.GH_PAT }}
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
|
6
|
+
Style/EachWithObject:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/ParallelAssignment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Alias:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/LambdaCall:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/StabbyLambdaParentheses:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/FormatString:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/Documentation:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/SpaceInLambdaLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Layout/MultilineMethodCallIndentation:
|
35
|
+
Enabled: true
|
36
|
+
EnforcedStyle: indented
|
37
|
+
|
38
|
+
Metrics/LineLength:
|
39
|
+
Max: 100
|
40
|
+
|
41
|
+
Metrics/MethodLength:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Metrics/ClassLength:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Metrics/BlockLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/AbcSize:
|
51
|
+
Max: 20
|
52
|
+
|
53
|
+
Metrics/CyclomaticComplexity:
|
54
|
+
Enabled: true
|
55
|
+
Max: 10
|
56
|
+
|
57
|
+
Lint/BooleanSymbol:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/AccessModifierDeclarations:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/BlockDelimiters:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Layout/IndentFirstArrayElement:
|
67
|
+
EnforcedStyle: consistent
|
68
|
+
|
69
|
+
Style/ClassAndModuleChildren:
|
70
|
+
Exclude:
|
71
|
+
- "spec/**/*_spec.rb"
|
72
|
+
|
73
|
+
Lint/HandleExceptions:
|
74
|
+
Exclude:
|
75
|
+
- "spec/spec_helper.rb"
|
76
|
+
|
77
|
+
Naming/PredicateName:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Naming/FileName:
|
81
|
+
Exclude:
|
82
|
+
- "lib/dry-*.rb"
|
83
|
+
|
84
|
+
Style/SymbolArray:
|
85
|
+
Exclude:
|
86
|
+
- "spec/**/*_spec.rb"
|
87
|
+
|
88
|
+
Style/ConditionalAssignment:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
Naming/MethodName:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
Style/AsciiComments:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
Style/DateTime:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
Style/IfUnlessModifier:
|
101
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
+
# 0.8.3 / 2020-01-07
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- Delegation warnings about keyword arguments (flash-gordon)
|
6
|
+
|
7
|
+
[Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-matcher/compare/v0.8.2...v0.8.3)
|
8
|
+
|
1
9
|
# 0.8.2 / 2019-09-06
|
2
10
|
|
3
11
|
## Fixed
|
4
12
|
|
5
13
|
- Minimal dry-core version set to 0.4.8 (flash-gordon)
|
6
14
|
|
15
|
+
[Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-matcher/compare/v0.8.1...v0.8.2)
|
16
|
+
|
7
17
|
# 0.8.1 / 2019-08-13
|
8
18
|
|
9
19
|
## Added
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Issue Guidelines
|
2
|
+
|
3
|
+
## Reporting bugs
|
4
|
+
|
5
|
+
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
+
|
7
|
+
## Reporting feature requests
|
8
|
+
|
9
|
+
Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
+
|
11
|
+
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
+
|
13
|
+
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
|
+
|
15
|
+
# Pull Request Guidelines
|
16
|
+
|
17
|
+
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
+
|
19
|
+
Other requirements:
|
20
|
+
|
21
|
+
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
+
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
+
3) Add API documentation if it's a new feature
|
24
|
+
4) Update API documentation if it changes an existing feature
|
25
|
+
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
+
|
27
|
+
# Asking for help
|
28
|
+
|
29
|
+
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
|
data/Gemfile
CHANGED
@@ -2,21 +2,17 @@
|
|
2
2
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
|
5
|
+
eval_gemfile 'Gemfile.devtools'
|
6
6
|
|
7
|
-
|
8
|
-
gem 'rake'
|
9
|
-
gem 'yard'
|
7
|
+
gemspec
|
10
8
|
|
11
9
|
group :test do
|
12
|
-
gem 'codeclimate-test-reporter'
|
13
10
|
gem 'dry-monads', '~> 1.2.0'
|
14
11
|
gem 'rspec', '~> 3.8'
|
15
|
-
gem 'simplecov'
|
16
12
|
end
|
17
13
|
|
18
14
|
group :tools do
|
15
|
+
gem 'yard'
|
19
16
|
gem 'byebug', platform: :mri
|
20
17
|
gem 'pry'
|
21
|
-
gem 'rubocop', require: false
|
22
18
|
end
|
data/Gemfile.devtools
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
2
|
+
|
3
|
+
gem "ossy", github: "solnic/ossy", branch: "master", platforms: :ruby
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'codacy-coverage', require: false, platforms: :ruby
|
7
|
+
gem 'simplecov', require: false, platforms: :ruby
|
8
|
+
gem 'warning'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :tools do
|
12
|
+
# this is the same version that we use on codacy
|
13
|
+
gem 'rubocop', '0.71.0'
|
14
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2020 dry-rb team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
-
[gitter]: https://gitter.im/dry-rb/chat
|
2
1
|
[gem]: https://rubygems.org/gems/dry-matcher
|
3
|
-
[
|
2
|
+
[actions]: https://github.com/dry-rb/dry-matcher/actions
|
3
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-matcher
|
4
4
|
[chat]: https://dry-rb.zulipchat.com
|
5
|
-
[
|
6
|
-
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-matcher/maintainability
|
7
|
-
[coverage]: https://codeclimate.com/github/dry-rb/dry-matcher/test_coverage
|
5
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-matcher
|
8
6
|
|
9
7
|
# dry-matcher [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
10
8
|
|
11
|
-
[![Gem Version](https://
|
12
|
-
[![
|
13
|
-
[![
|
14
|
-
[![
|
15
|
-
[![
|
16
|
-
|
17
|
-
Flexible, expressive pattern matching for Ruby.
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/dry-matcher.svg)][gem]
|
10
|
+
[![CI Status](https://github.com/dry-rb/dry-matcher/workflows/ci/badge.svg)][actions]
|
11
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f09a7d1745fd430d829a1f825357db88)][codacy]
|
12
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f09a7d1745fd430d829a1f825357db88)][codacy]
|
13
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-matcher.svg?branch=master)][inchpages]
|
18
14
|
|
19
15
|
## Links
|
20
16
|
|
21
|
-
|
17
|
+
* [User documentation](http://dry-rb.org/gems/dry-matcher)
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-matcher)
|
19
|
+
|
20
|
+
## Supported Ruby versions
|
21
|
+
|
22
|
+
This library officially supports the following Ruby versions:
|
23
|
+
|
24
|
+
* MRI >= `2.4`
|
25
|
+
* jruby >= `9.2`
|
22
26
|
|
23
27
|
## License
|
24
28
|
|
25
|
-
|
29
|
+
See `LICENSE` file.
|
data/Rakefile
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
title: Class enhancement
|
3
|
+
layout: gem-single
|
4
|
+
name: dry-matcher
|
5
|
+
---
|
6
|
+
|
7
|
+
You can offer a match block API from your own methods using `Dry::Matcher.for`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "dry-matcher"
|
11
|
+
|
12
|
+
# First, build a matcher or use an existing one (like dry-matcher's ResultMatcher)
|
13
|
+
MyMatcher = Dry::Matcher.new(...)
|
14
|
+
|
15
|
+
# Offer it from your class with `Dry::Matcher.for`
|
16
|
+
class MyOperation
|
17
|
+
include Dry::Matcher.for(:call, with: MyMatcher)
|
18
|
+
|
19
|
+
def call
|
20
|
+
# return a value here
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# And now `MyOperation#call` offers the matcher block API
|
25
|
+
operation = MyOperation.new
|
26
|
+
|
27
|
+
operation.() do |m|
|
28
|
+
# Use the matcher's API here
|
29
|
+
end
|
30
|
+
```
|
@@ -0,0 +1,89 @@
|
|
1
|
+
---
|
2
|
+
title: Introduction
|
3
|
+
description: Expressive match API for operating on computation results
|
4
|
+
layout: gem-single
|
5
|
+
type: gem
|
6
|
+
name: dry-matcher
|
7
|
+
sections:
|
8
|
+
- class-enhancement
|
9
|
+
- result-matcher
|
10
|
+
---
|
11
|
+
|
12
|
+
dry-matcher offers flexible, expressive pattern matching for Ruby.
|
13
|
+
|
14
|
+
You can build your own matcher or use the out-of-the-box support for matching on [dry-monads](/gems/dry-monads) `Result` values.
|
15
|
+
|
16
|
+
## Building a matcher
|
17
|
+
|
18
|
+
To build your own matcher, create a series of "case" objects with their own resolving logic. First argument of the case block is the value to match, second argument is the list of patterns (see below). The block must either return the result or `Dry::Matcher::Undefined` if the has no match. The latter signals dry-matcher to try the next case.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "dry-matcher"
|
22
|
+
|
23
|
+
# Match `[:ok, some_value]` for success
|
24
|
+
success_case = Dry::Matcher::Case.new do |(code, value), _|
|
25
|
+
if code.equal?(:ok)
|
26
|
+
value
|
27
|
+
else
|
28
|
+
# this is a constant from dry/core/constants
|
29
|
+
Dry::Matcher::Undefined
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Match `[:err, some_error_code, some_value]` for failure
|
34
|
+
failure_case = Dry::Matcher::Case.new do |(code, value), patterns|
|
35
|
+
if code.equal?(:err) && (patterns.empty? || patterns.include?(value))
|
36
|
+
value
|
37
|
+
else
|
38
|
+
Dry::Matcher::Undefined
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Build the matcher
|
43
|
+
matcher = Dry::Matcher.new(success: success_case, failure: failure_case)
|
44
|
+
```
|
45
|
+
|
46
|
+
Then use these cases as part of an API to match on results:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
my_success = [:ok, "success!"]
|
50
|
+
|
51
|
+
result = matcher.(my_success) do |m|
|
52
|
+
m.success do |v|
|
53
|
+
"Yay: #{v}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# :not_found and :lost are patterns
|
57
|
+
m.failure :not_found, :lost do |v|
|
58
|
+
"Oops, not found: #{v}"
|
59
|
+
end
|
60
|
+
|
61
|
+
m.failure do |v|
|
62
|
+
"Boo: #{v}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
result # => "Yay: success!"
|
67
|
+
```
|
68
|
+
|
69
|
+
Cases are executed in order. The first match wins and halts subsequent matching.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
my_failure = [:err, :not_found, "missing!"]
|
73
|
+
|
74
|
+
result = matcher.(my_failure) do |m|
|
75
|
+
m.success do |v|
|
76
|
+
"Yay: #{v}"
|
77
|
+
end
|
78
|
+
|
79
|
+
m.failure :not_found do |v|
|
80
|
+
"Oops, not found: #{v}"
|
81
|
+
end
|
82
|
+
|
83
|
+
m.failure do |v|
|
84
|
+
"Boo: #{v}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
result # => "Oops, not found: missing!"
|
89
|
+
```
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
title: Result matcher
|
3
|
+
layout: gem-single
|
4
|
+
name: dry-matcher
|
5
|
+
---
|
6
|
+
|
7
|
+
dry-matcher provides a ready-to-use `ResultMatcher` for working with `Result` or `Try` monads from [dry-monads](/gems/dry-monads) or any other compatible gems.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "dry/monads/result"
|
11
|
+
require "dry/matcher/result_matcher"
|
12
|
+
|
13
|
+
value = Dry::Monads::Success("success!")
|
14
|
+
|
15
|
+
result = Dry::Matcher::ResultMatcher.(value) do |m|
|
16
|
+
m.success(Integer) do |i|
|
17
|
+
"Got int: #{i}"
|
18
|
+
end
|
19
|
+
|
20
|
+
m.success do |v|
|
21
|
+
"Yay: #{v}"
|
22
|
+
end
|
23
|
+
|
24
|
+
m.failure :not_found do |_err, reason|
|
25
|
+
"Nope: #{reason}"
|
26
|
+
end
|
27
|
+
|
28
|
+
m.failure do |v|
|
29
|
+
"Boo: #{v}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
result # => "Yay: success!"
|
34
|
+
```
|
data/dry-matcher.gemspec
CHANGED
data/lib/dry/matcher.rb
CHANGED
@@ -9,6 +9,8 @@ module Dry
|
|
9
9
|
class Matcher
|
10
10
|
include Core::Constants
|
11
11
|
|
12
|
+
RUBY2_KEYWORDS = respond_to?(:ruby2_keywords, true)
|
13
|
+
|
12
14
|
# Generates a module containing pattern matching for methods listed in
|
13
15
|
# `match_methods` argument with behavior defined by `with` matcher
|
14
16
|
#
|
@@ -45,6 +47,7 @@ module Dry
|
|
45
47
|
result
|
46
48
|
end
|
47
49
|
end
|
50
|
+
ruby2_keywords(match_method) if RUBY2_KEYWORDS
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
data/lib/dry/matcher/version.rb
CHANGED
data/project.yml
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-core
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 0.4.8
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '13.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '13.0'
|
28
42
|
description: Flexible, expressive pattern matching for Ruby
|
29
43
|
email:
|
30
44
|
- tim@icelab.com.au
|
@@ -34,15 +48,28 @@ extensions: []
|
|
34
48
|
extra_rdoc_files: []
|
35
49
|
files:
|
36
50
|
- ".codeclimate.yml"
|
51
|
+
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
52
|
+
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
53
|
+
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
54
|
+
- ".github/workflows/ci.yml"
|
55
|
+
- ".github/workflows/docsite.yml"
|
56
|
+
- ".github/workflows/sync_configs.yml"
|
37
57
|
- ".gitignore"
|
38
58
|
- ".rspec"
|
39
|
-
- ".
|
59
|
+
- ".rubocop.yml"
|
40
60
|
- ".yardopts"
|
41
61
|
- CHANGELOG.md
|
62
|
+
- CODE_OF_CONDUCT.md
|
63
|
+
- CONTRIBUTING.md
|
42
64
|
- Gemfile
|
65
|
+
- Gemfile.devtools
|
66
|
+
- LICENSE
|
43
67
|
- LICENSE.md
|
44
68
|
- README.md
|
45
69
|
- Rakefile
|
70
|
+
- docsite/source/class-enhancement.html.md
|
71
|
+
- docsite/source/index.html.md
|
72
|
+
- docsite/source/result-matcher.html.md
|
46
73
|
- dry-matcher.gemspec
|
47
74
|
- lib/dry-matcher.rb
|
48
75
|
- lib/dry/matcher.rb
|
@@ -51,6 +78,7 @@ files:
|
|
51
78
|
- lib/dry/matcher/evaluator.rb
|
52
79
|
- lib/dry/matcher/result_matcher.rb
|
53
80
|
- lib/dry/matcher/version.rb
|
81
|
+
- project.yml
|
54
82
|
homepage: http://dry-rb.org/gems/dry-matcher
|
55
83
|
licenses:
|
56
84
|
- MIT
|
@@ -70,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
98
|
- !ruby/object:Gem::Version
|
71
99
|
version: '0'
|
72
100
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.1.2
|
74
102
|
signing_key:
|
75
103
|
specification_version: 4
|
76
104
|
summary: Flexible, expressive pattern matching for Ruby
|
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
bundler_args: --without tools
|
4
|
-
before_script:
|
5
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
6
|
-
- chmod +x ./cc-test-reporter
|
7
|
-
- ./cc-test-reporter before-build
|
8
|
-
after_script:
|
9
|
-
- "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
10
|
-
rvm:
|
11
|
-
- 2.4.6
|
12
|
-
- 2.5.5
|
13
|
-
- 2.6.3
|
14
|
-
- jruby-9.2.7.0
|
15
|
-
env:
|
16
|
-
global:
|
17
|
-
- COVERAGE=true
|
18
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
-
notifications:
|
20
|
-
email: false
|