dry-equalizer 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +12 -0
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +34 -0
- data/.rspec +2 -4
- data/.rubocop.yml +89 -0
- data/CHANGELOG.md +31 -1
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +6 -4
- data/LICENSE +17 -18
- data/README.md +21 -26
- data/docsite/source/index.html.md +86 -0
- data/dry-equalizer.gemspec +2 -4
- data/lib/dry/equalizer.rb +31 -15
- data/lib/dry/equalizer/version.rb +2 -2
- data/spec/spec_helper.rb +4 -10
- data/spec/unit/equalizer/universal_spec.rb +48 -3
- metadata +14 -28
- data/.travis.yml +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e167f2f667d5c3e4bf962263e4285d327c9e29aacc650c4f70debbeb1af29df
|
4
|
+
data.tar.gz: 55c6c4b07d8a4474070bfe4a964ef29f8725ba7798c3abf4e40e82db48b4eea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998bd2189807358dd8d1b44e30d9eb8cd634e908f7a51be3a6151af18d41a2333c3abac36f4781cec9008c55904cd890d96659cfd2a0b2eb1580d3c2af82b8dd
|
7
|
+
data.tar.gz: 7b8a7f6f5840ba503f4574b4f279f73641632ee0faf8eab8c57db44e9ceda51a7fef200112dc59dffff7a7d1fcc7e11ba8eba9951a2d0023437b935903692e25
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,34 @@
|
|
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 [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
|
13
|
+
|
14
|
+
**Before you report**
|
15
|
+
|
16
|
+
:warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
|
17
|
+
|
18
|
+
**Describe the bug**
|
19
|
+
|
20
|
+
A clear and concise description of what the bug is.
|
21
|
+
|
22
|
+
**To Reproduce**
|
23
|
+
|
24
|
+
Provide detailed steps to reproduce, an executable script would be best.
|
25
|
+
|
26
|
+
**Expected behavior**
|
27
|
+
|
28
|
+
A clear and concise description of what you expected to happen.
|
29
|
+
|
30
|
+
**Your environment**
|
31
|
+
|
32
|
+
- Affects my production application: **YES/NO**
|
33
|
+
- Ruby version: ...
|
34
|
+
- 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,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,34 @@
|
|
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: Update configuration files from devtools
|
15
|
+
env:
|
16
|
+
GITHUB_LOGIN: dry-bot
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
18
|
+
run: |
|
19
|
+
git clone https://github.com/dry-rb/devtools.git tmp/devtools
|
20
|
+
|
21
|
+
if [ -f ".github/workflows/custom_ci.yml" ]; then
|
22
|
+
rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
|
23
|
+
else
|
24
|
+
rsync -av tmp/devtools/shared/ . ;
|
25
|
+
fi
|
26
|
+
|
27
|
+
git config --local user.email "dry-bot@dry-rb.org"
|
28
|
+
git config --local user.name "dry-bot"
|
29
|
+
git add -A
|
30
|
+
git commit -m "[devtools] config sync" || echo "nothing changed"
|
31
|
+
- name: Push changes
|
32
|
+
uses: ad-m/github-push-action@master
|
33
|
+
with:
|
34
|
+
github_token: ${{ secrets.GH_PAT }}
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -0,0 +1,89 @@
|
|
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/Alias:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/LambdaCall:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/StabbyLambdaParentheses:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FormatString:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/SpaceInLambdaLiteral:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/MultilineMethodCallIndentation:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyle: indented
|
34
|
+
|
35
|
+
Metrics/LineLength:
|
36
|
+
Max: 100
|
37
|
+
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Max: 22
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Max: 150
|
43
|
+
|
44
|
+
Metrics/AbcSize:
|
45
|
+
Max: 20
|
46
|
+
|
47
|
+
Metrics/BlockLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/CyclomaticComplexity:
|
51
|
+
Enabled: true
|
52
|
+
Max: 10
|
53
|
+
|
54
|
+
Lint/BooleanSymbol:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/AccessModifierDeclarations:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/BlockDelimiters:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Layout/IndentFirstArrayElement:
|
64
|
+
EnforcedStyle: consistent
|
65
|
+
|
66
|
+
Style/ClassAndModuleChildren:
|
67
|
+
Exclude:
|
68
|
+
- "spec/**/*_spec.rb"
|
69
|
+
|
70
|
+
Lint/HandleExceptions:
|
71
|
+
Exclude:
|
72
|
+
- "spec/spec_helper.rb"
|
73
|
+
|
74
|
+
Naming/FileName:
|
75
|
+
Exclude:
|
76
|
+
- "lib/dry-*.rb"
|
77
|
+
|
78
|
+
Style/SymbolArray:
|
79
|
+
Exclude:
|
80
|
+
- "spec/**/*_spec.rb"
|
81
|
+
|
82
|
+
Style/ConditionalAssignment:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Naming/MethodName:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Style/AsciiComments:
|
89
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,38 @@
|
|
1
|
+
# v0.3.0 2019-11-07
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
- [BREAKING] Dropped support for Ruby < 2.4
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Memoization option for immutable objects. If `immutable: true` is passed the result of `.hash` call will be memoized after its first invokation or on `.freeze` call (skryukov)
|
10
|
+
```ruby
|
11
|
+
class User
|
12
|
+
include Dry::Equalizer(:id, :name, :age, immutable: true)
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
[Compare v0.2.2...v0.3.0](https://github.com/dry-rb/dry-equalizer/compare/v0.2.2...v0.3.0)
|
17
|
+
|
18
|
+
# v0.2.2 2019-03-08
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- Generation of `#to_s` and `#inspect` can be disabled with `inspect: false` (flash-gordon)
|
23
|
+
```ruby
|
24
|
+
class User
|
25
|
+
include Dry::Equalizer(:id, :name, :age, inspect: false)
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
[Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-equalizer/compare/v0.2.1...v0.2.2)
|
30
|
+
|
1
31
|
# v0.2.1 2018-04-26
|
2
32
|
|
3
33
|
### Fixed
|
4
34
|
|
5
|
-
|
35
|
+
- Including equalizer module with same keys multiple times won't cause duped keys in `inspect` output (radar)
|
6
36
|
|
7
37
|
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-equalizer/compare/v0.2.0...v0.2.1)
|
8
38
|
|
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
CHANGED
@@ -6,11 +6,11 @@ If you found a bug, report an issue and describe what's the expected behavior ve
|
|
6
6
|
|
7
7
|
## Reporting feature requests
|
8
8
|
|
9
|
-
Report a feature request **only after discussing it first on [
|
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
10
|
|
11
11
|
## Reporting questions, support requests, ideas, concerns etc.
|
12
12
|
|
13
|
-
**PLEASE DON'T** - use [
|
13
|
+
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
14
|
|
15
15
|
# Pull Request Guidelines
|
16
16
|
|
@@ -26,4 +26,4 @@ Other requirements:
|
|
26
26
|
|
27
27
|
# Asking for help
|
28
28
|
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [
|
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
@@ -3,13 +3,15 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
+
gem 'bundler'
|
6
7
|
gem 'rake'
|
7
8
|
gem 'rspec', '~> 3.5'
|
8
9
|
end
|
9
10
|
|
10
11
|
group :test do
|
11
|
-
platform :mri
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
gem 'simplecov', require: false, platform: :mri
|
13
|
+
end
|
14
|
+
|
15
|
+
group :tools do
|
16
|
+
gem 'ossy', git: 'https://github.com/solnic/ossy.git', branch: 'master', platform: :mri
|
15
17
|
end
|
data/LICENSE
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
|
2
|
-
Copyright (c) 2012 Markus Schirp (packaging)
|
1
|
+
The MIT License (MIT)
|
3
2
|
|
4
|
-
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
3
|
+
Copyright (c) 2015-2019 dry-rb team
|
11
4
|
|
12
|
-
|
13
|
-
|
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:
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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,21 +1,20 @@
|
|
1
|
-
|
1
|
+
[gem]: https://rubygems.org/gems/dry-equalizer
|
2
|
+
[ci]: https://github.com/dry-rb/dry-equalizer/actions?query=workflow%3Aci
|
3
|
+
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-equalizer
|
4
|
+
[chat]: https://dry-rb.zulipchat.com
|
5
|
+
|
6
|
+
# dry-equalizer [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
2
7
|
|
3
8
|
Module to define equality, equivalence and inspection methods
|
4
9
|
|
5
10
|
[![Gem Version](http://img.shields.io/gem/v/dry-equalizer.svg)][gem]
|
6
|
-
[![Build Status](
|
7
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/maintainability)]
|
8
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/test_coverage)]
|
9
|
-
|
10
|
-
[gem]: https://rubygems.org/gems/dry-equalizer
|
11
|
-
[travis]: https://travis-ci.org/dry-rb/dry-equalizer
|
12
|
-
[gemnasium]: https://gemnasium.com/dry-rb/dry-equalizer
|
13
|
-
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-equalizer
|
11
|
+
[![Build Status](https://github.com/dry-rb/dry-equalizer/workflows/ci/badge.svg)][ci]
|
12
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/maintainability)][codeclimate]
|
13
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/test_coverage)][codeclimate]
|
14
14
|
|
15
|
-
Examples
|
16
|
-
--------
|
15
|
+
## Examples
|
17
16
|
|
18
|
-
```
|
17
|
+
```ruby
|
19
18
|
class GeoLocation
|
20
19
|
include Dry::Equalizer(:latitude, :longitude)
|
21
20
|
|
@@ -43,14 +42,13 @@ point_a.eql?(point_c) # => false
|
|
43
42
|
point_a.equal?(point_c) # => false
|
44
43
|
```
|
45
44
|
|
46
|
-
Supported Ruby Versions
|
47
|
-
-----------------------
|
45
|
+
## Supported Ruby Versions
|
48
46
|
|
49
47
|
This library aims to support and is [tested against][travis] the following Ruby
|
50
48
|
implementations:
|
51
49
|
|
52
|
-
|
53
|
-
|
50
|
+
- MRI 2.4+
|
51
|
+
- JRuby 9.x
|
54
52
|
|
55
53
|
If something doesn't work on one of these versions, it's a bug.
|
56
54
|
|
@@ -66,22 +64,19 @@ patches in a timely fashion. If critical issues for a particular implementation
|
|
66
64
|
exist at the time of a major release, support for that Ruby version may be
|
67
65
|
dropped.
|
68
66
|
|
69
|
-
Credits
|
70
|
-
-------
|
67
|
+
## Credits
|
71
68
|
|
72
69
|
This is a fork of the original [equalizer](https://github.com/dkubb/equalizer).
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
- Dan Kubb ([dkubb](https://github.com/dkubb))
|
72
|
+
- Piotr Solnica ([solnic](https://github.com/solnic))
|
73
|
+
- Markus Schirp ([mbj](https://github.com/mbj))
|
74
|
+
- Erik Michaels-Ober ([sferik](https://github.com/sferik))
|
78
75
|
|
79
|
-
Contributing
|
80
|
-
-------------
|
76
|
+
## Contributing
|
81
77
|
|
82
78
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
83
79
|
|
84
|
-
Copyright
|
85
|
-
---------
|
80
|
+
## Copyright
|
86
81
|
|
87
82
|
Copyright © 2009-2013 Dan Kubb. See LICENSE for details.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
---
|
2
|
+
title: Introduction & Usage
|
3
|
+
description: Simple mixin providing equality, equivalence and inspection methods
|
4
|
+
layout: gem-single
|
5
|
+
order: 5
|
6
|
+
type: gem
|
7
|
+
name: dry-equalizer
|
8
|
+
---
|
9
|
+
|
10
|
+
`dry-equalizer` is a simple mixin that can be used to add instance variable based equality, equivalence and inspection methods to your objects.
|
11
|
+
|
12
|
+
### Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'dry-equalizer'
|
16
|
+
|
17
|
+
class GeoLocation
|
18
|
+
include Dry::Equalizer(:latitude, :longitude)
|
19
|
+
|
20
|
+
attr_reader :latitude, :longitude
|
21
|
+
|
22
|
+
def initialize(latitude, longitude)
|
23
|
+
@latitude, @longitude = latitude, longitude
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
point_a = GeoLocation.new(1, 2)
|
28
|
+
point_b = GeoLocation.new(1, 2)
|
29
|
+
point_c = GeoLocation.new(2, 2)
|
30
|
+
|
31
|
+
point_a.inspect # => "#<GeoLocation latitude=1 longitude=2>"
|
32
|
+
|
33
|
+
point_a == point_b # => true
|
34
|
+
point_a.hash == point_b.hash # => true
|
35
|
+
point_a.eql?(point_b) # => true
|
36
|
+
point_a.equal?(point_b) # => false
|
37
|
+
|
38
|
+
point_a == point_c # => false
|
39
|
+
point_a.hash == point_c.hash # => false
|
40
|
+
point_a.eql?(point_c) # => false
|
41
|
+
point_a.equal?(point_c) # => false
|
42
|
+
```
|
43
|
+
|
44
|
+
### Configuration options
|
45
|
+
|
46
|
+
#### `inspect`
|
47
|
+
|
48
|
+
Use `inspect` option to skip `#inspect` method overloading:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class Foo
|
52
|
+
include Dry::Equalizer(:a, inspect: false)
|
53
|
+
|
54
|
+
attr_reader :a, :b
|
55
|
+
|
56
|
+
def initialize(a, b)
|
57
|
+
@a, @b = a, b
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Foo.new(1, 2).inspect
|
62
|
+
# => "#<Foo:0x00007fbc9c0487f0 @a=1, @b=2>"
|
63
|
+
```
|
64
|
+
|
65
|
+
#### `immutable`
|
66
|
+
|
67
|
+
For objects that are immutable it doesn't make sense to calculate `#hash` every time it's called. To memoize hash use `immutable` option:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class ImmutableHash
|
71
|
+
include Dry::Equalizer(:foo, :bar, immutable: true)
|
72
|
+
|
73
|
+
attr_accessor :foo, :bar
|
74
|
+
|
75
|
+
def initialize(foo, bar)
|
76
|
+
@foo, @bar = foo, bar
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
obj = ImmutableHash.new('foo', 'bar')
|
81
|
+
old_hash = obj.hash
|
82
|
+
obj.foo = 'changed'
|
83
|
+
old_hash == obj.hash
|
84
|
+
# => true
|
85
|
+
```
|
86
|
+
|
data/dry-equalizer.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.email = %w[dan.kubb@gmail.com mbj@schirp-dso.com]
|
8
8
|
gem.description = 'Module to define equality, equivalence and inspection methods'
|
9
9
|
gem.summary = gem.description
|
10
|
-
gem.homepage = 'https://github.com/
|
10
|
+
gem.homepage = 'https://github.com/dry-rb/dry-equalizer'
|
11
11
|
gem.licenses = 'MIT'
|
12
12
|
|
13
13
|
gem.require_paths = %w[lib]
|
@@ -15,7 +15,5 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = `git ls-files -- spec/{unit,integration}`.split("\n")
|
16
16
|
gem.extra_rdoc_files = %w[LICENSE README.md CONTRIBUTING.md]
|
17
17
|
|
18
|
-
gem.required_ruby_version = '>= 2.
|
19
|
-
|
20
|
-
gem.add_development_dependency('bundler', '~> 1.3', '>= 1.3.5')
|
18
|
+
gem.required_ruby_version = '>= 2.4.0'
|
21
19
|
end
|
data/lib/dry/equalizer.rb
CHANGED
@@ -2,8 +2,8 @@ module Dry
|
|
2
2
|
# Build an equalizer module for the inclusion in other class
|
3
3
|
#
|
4
4
|
# @api public
|
5
|
-
def self.Equalizer(*keys)
|
6
|
-
Dry::Equalizer.new(*keys)
|
5
|
+
def self.Equalizer(*keys, **options)
|
6
|
+
Dry::Equalizer.new(*keys, **options)
|
7
7
|
end
|
8
8
|
|
9
9
|
# Define equality, equivalence and inspection methods
|
@@ -14,13 +14,16 @@ module Dry
|
|
14
14
|
# #hash, and #inspect
|
15
15
|
#
|
16
16
|
# @param [Array<Symbol>] keys
|
17
|
+
# @param [Hash] options
|
18
|
+
# @option options [Boolean] :inspect whether to define #inspect method
|
19
|
+
# @option options [Boolean] :immutable whether to memoize #hash method
|
17
20
|
#
|
18
21
|
# @return [undefined]
|
19
22
|
#
|
20
23
|
# @api private
|
21
|
-
def initialize(*keys)
|
24
|
+
def initialize(*keys, **options)
|
22
25
|
@keys = keys.uniq
|
23
|
-
define_methods
|
26
|
+
define_methods(**options)
|
24
27
|
freeze
|
25
28
|
end
|
26
29
|
|
@@ -36,18 +39,21 @@ module Dry
|
|
36
39
|
# @api private
|
37
40
|
def included(descendant)
|
38
41
|
super
|
39
|
-
descendant.
|
42
|
+
descendant.include Methods
|
40
43
|
end
|
41
44
|
|
42
45
|
# Define the equalizer methods based on #keys
|
43
46
|
#
|
47
|
+
# @param [Boolean] inspect whether to define #inspect method
|
48
|
+
# @param [Boolean] immutable whether to memoize #hash method
|
49
|
+
#
|
44
50
|
# @return [undefined]
|
45
51
|
#
|
46
52
|
# @api private
|
47
|
-
def define_methods
|
53
|
+
def define_methods(inspect: true, immutable: false)
|
48
54
|
define_cmp_method
|
49
|
-
define_hash_method
|
50
|
-
define_inspect_method
|
55
|
+
define_hash_method(immutable: immutable)
|
56
|
+
define_inspect_method if inspect
|
51
57
|
end
|
52
58
|
|
53
59
|
# Define an #cmp? method based on the instance's values identified by #keys
|
@@ -70,10 +76,20 @@ module Dry
|
|
70
76
|
# @return [undefined]
|
71
77
|
#
|
72
78
|
# @api private
|
73
|
-
def define_hash_method
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
def define_hash_method(immutable:)
|
80
|
+
calculate_hash = ->(obj) { @keys.map { |key| obj.__send__(key) }.push(obj.class).hash }
|
81
|
+
if immutable
|
82
|
+
define_method(:hash) do
|
83
|
+
@__hash__ ||= calculate_hash.call(self)
|
84
|
+
end
|
85
|
+
define_method(:freeze) do
|
86
|
+
hash
|
87
|
+
super()
|
88
|
+
end
|
89
|
+
else
|
90
|
+
define_method(:hash) do
|
91
|
+
calculate_hash.call(self)
|
92
|
+
end
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
@@ -84,7 +100,7 @@ module Dry
|
|
84
100
|
# @api private
|
85
101
|
def define_inspect_method
|
86
102
|
keys = @keys
|
87
|
-
define_method(:inspect) do
|
103
|
+
define_method(:inspect) do
|
88
104
|
klass = self.class
|
89
105
|
name = klass.name || klass.inspect
|
90
106
|
"#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>"
|
@@ -122,6 +138,6 @@ module Dry
|
|
122
138
|
def ==(other)
|
123
139
|
other.is_a?(self.class) && cmp?(__method__, other)
|
124
140
|
end
|
125
|
-
end
|
126
|
-
end
|
141
|
+
end
|
142
|
+
end
|
127
143
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
if
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
if RUBY_VERSION == latest_mri
|
7
|
-
require 'simplecov'
|
8
|
-
SimpleCov.start do
|
9
|
-
add_filter '/spec/'
|
10
|
-
end
|
1
|
+
if ENV['COVERAGE'] == 'true'
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/spec/'
|
11
5
|
end
|
12
6
|
end
|
13
7
|
|
@@ -10,7 +10,7 @@ RSpec.describe Dry::Equalizer do
|
|
10
10
|
before do
|
11
11
|
# specify the class #name method
|
12
12
|
allow(klass).to receive(:name).and_return(name)
|
13
|
-
klass.
|
13
|
+
klass.include(subject)
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:instance) { klass.new }
|
@@ -80,6 +80,7 @@ RSpec.describe Dry::Equalizer do
|
|
80
80
|
let(:klass) do
|
81
81
|
::Class.new do
|
82
82
|
attr_reader :firstname, :lastname
|
83
|
+
attr_writer :firstname
|
83
84
|
private :firstname, :lastname
|
84
85
|
|
85
86
|
def initialize(firstname, lastname)
|
@@ -92,7 +93,7 @@ RSpec.describe Dry::Equalizer do
|
|
92
93
|
before do
|
93
94
|
# specify the class #inspect method
|
94
95
|
allow(klass).to receive_messages(name: nil, inspect: name)
|
95
|
-
klass.
|
96
|
+
klass.include(subject)
|
96
97
|
end
|
97
98
|
|
98
99
|
it { should be_instance_of(described_class) }
|
@@ -151,6 +152,26 @@ RSpec.describe Dry::Equalizer do
|
|
151
152
|
.to eql('#<User firstname="John" lastname="Doe">')
|
152
153
|
end
|
153
154
|
end
|
155
|
+
|
156
|
+
context 'when immutable' do
|
157
|
+
describe '#hash' do
|
158
|
+
|
159
|
+
subject { Dry::Equalizer(*keys, immutable: true) }
|
160
|
+
|
161
|
+
it 'returns memoized hash' do
|
162
|
+
expect { instance.firstname = 'Changed' }.not_to(change { instance.hash })
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when frozen' do
|
166
|
+
it 'returns memoized hash' do
|
167
|
+
instance.freeze
|
168
|
+
|
169
|
+
expect(instance.hash)
|
170
|
+
.to eql([firstname, lastname, klass].hash)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
154
175
|
end
|
155
176
|
|
156
177
|
context 'with duplicate keys' do
|
@@ -176,7 +197,7 @@ RSpec.describe Dry::Equalizer do
|
|
176
197
|
before do
|
177
198
|
# specify the class #inspect method
|
178
199
|
allow(klass).to receive_messages(name: nil, inspect: name)
|
179
|
-
klass.
|
200
|
+
klass.include(subject)
|
180
201
|
end
|
181
202
|
|
182
203
|
it { should be_instance_of(described_class) }
|
@@ -190,4 +211,28 @@ RSpec.describe Dry::Equalizer do
|
|
190
211
|
end
|
191
212
|
end
|
192
213
|
end
|
214
|
+
|
215
|
+
context 'with options' do
|
216
|
+
context 'w/o inspect' do
|
217
|
+
subject { Dry::Equalizer(*keys, inspect: false) }
|
218
|
+
|
219
|
+
let(:keys) { %i[firstname lastname].freeze }
|
220
|
+
let(:firstname) { 'John' }
|
221
|
+
let(:lastname) { 'Doe' }
|
222
|
+
let(:instance) { klass.new(firstname, lastname) }
|
223
|
+
|
224
|
+
let(:klass) do
|
225
|
+
::Struct.new(:firstname, :lastname)
|
226
|
+
end
|
227
|
+
|
228
|
+
before { klass.include(subject) }
|
229
|
+
|
230
|
+
describe '#inspect' do
|
231
|
+
it 'returns the default string' do
|
232
|
+
expect(instance.inspect).to eql('#<struct firstname="John", lastname="Doe">')
|
233
|
+
expect(instance.to_s).to eql('#<struct firstname="John", lastname="Doe">')
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
193
238
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-equalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Kubb
|
@@ -9,28 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.3'
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.3.5
|
24
|
-
type: :development
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
requirements:
|
28
|
-
- - "~>"
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '1.3'
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.3.5
|
12
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
34
14
|
description: Module to define equality, equivalence and inspection methods
|
35
15
|
email:
|
36
16
|
- dan.kubb@gmail.com
|
@@ -42,17 +22,24 @@ extra_rdoc_files:
|
|
42
22
|
- README.md
|
43
23
|
- CONTRIBUTING.md
|
44
24
|
files:
|
25
|
+
- ".codeclimate.yml"
|
26
|
+
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
27
|
+
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
28
|
+
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
29
|
+
- ".github/workflows/docsite.yml"
|
30
|
+
- ".github/workflows/sync_configs.yml"
|
45
31
|
- ".gitignore"
|
46
32
|
- ".rspec"
|
47
33
|
- ".rubocop.yml"
|
48
|
-
- ".travis.yml"
|
49
34
|
- ".yardstick.yml"
|
50
35
|
- CHANGELOG.md
|
36
|
+
- CODE_OF_CONDUCT.md
|
51
37
|
- CONTRIBUTING.md
|
52
38
|
- Gemfile
|
53
39
|
- LICENSE
|
54
40
|
- README.md
|
55
41
|
- Rakefile
|
42
|
+
- docsite/source/index.html.md
|
56
43
|
- dry-equalizer.gemspec
|
57
44
|
- lib/dry-equalizer.rb
|
58
45
|
- lib/dry/equalizer.rb
|
@@ -63,7 +50,7 @@ files:
|
|
63
50
|
- spec/unit/equalizer/methods/eql_predicate_spec.rb
|
64
51
|
- spec/unit/equalizer/methods/equality_operator_spec.rb
|
65
52
|
- spec/unit/equalizer/universal_spec.rb
|
66
|
-
homepage: https://github.com/
|
53
|
+
homepage: https://github.com/dry-rb/dry-equalizer
|
67
54
|
licenses:
|
68
55
|
- MIT
|
69
56
|
metadata: {}
|
@@ -75,15 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
62
|
requirements:
|
76
63
|
- - ">="
|
77
64
|
- !ruby/object:Gem::Version
|
78
|
-
version: 2.
|
65
|
+
version: 2.4.0
|
79
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
67
|
requirements:
|
81
68
|
- - ">="
|
82
69
|
- !ruby/object:Gem::Version
|
83
70
|
version: '0'
|
84
71
|
requirements: []
|
85
|
-
|
86
|
-
rubygems_version: 2.7.4
|
72
|
+
rubygems_version: 3.0.6
|
87
73
|
signing_key:
|
88
74
|
specification_version: 4
|
89
75
|
summary: Module to define equality, equivalence and inspection methods
|
data/.travis.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
bundler_args: --without benchmarks tools
|
4
|
-
script:
|
5
|
-
- bundle exec rake
|
6
|
-
before_install:
|
7
|
-
- gem update --system
|
8
|
-
after_success:
|
9
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
10
|
-
rvm:
|
11
|
-
- 2.2.9
|
12
|
-
- 2.3.6
|
13
|
-
- 2.4.3
|
14
|
-
- 2.5.0
|
15
|
-
- jruby-9.1.15.0
|
16
|
-
env:
|
17
|
-
global:
|
18
|
-
- COVERAGE=true
|
19
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
20
|
-
notifications:
|
21
|
-
email: false
|
22
|
-
webhooks:
|
23
|
-
urls:
|
24
|
-
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
25
|
-
on_success: change # options: [always|never|change] default: always
|
26
|
-
on_failure: always # options: [always|never|change] default: always
|
27
|
-
on_start: false # default: false
|