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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a819572ea7edadec962667cf45602118b745509ee33a86bbf440153340500f6
4
- data.tar.gz: 725faa38c3a44a8ccb1a79e33e194f3aed15d2d08778167a90d144950d85718a
3
+ metadata.gz: 9e167f2f667d5c3e4bf962263e4285d327c9e29aacc650c4f70debbeb1af29df
4
+ data.tar.gz: 55c6c4b07d8a4474070bfe4a964ef29f8725ba7798c3abf4e40e82db48b4eea6
5
5
  SHA512:
6
- metadata.gz: 6b7145d6579f21bbd00dee972501f4251c60dea36f7e4c22eb4ea20ec640fe4e115b1ffc5da597354be807f2d844030a6ffa64a8712a660a543cb470f5801ddb
7
- data.tar.gz: 3d2bc74a8e66dee5e2873391a2a37a8768c063d5e36e17fca6dd5986129483ee7e2ba361335d4de65cd2c2b03070a8987e16eb6bae196dc89f9d5280f814c6ee
6
+ metadata.gz: 998bd2189807358dd8d1b44e30d9eb8cd634e908f7a51be3a6151af18d41a2333c3abac36f4781cec9008c55904cd890d96659cfd2a0b2eb1580d3c2af82b8dd
7
+ data.tar.gz: 7b8a7f6f5840ba503f4574b4f279f73641632ee0faf8eab8c57db44e9ceda51a7fef200112dc59dffff7a7d1fcc7e11ba8eba9951a2d0023437b935903692e25
data/.codeclimate.yml ADDED
@@ -0,0 +1,12 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ version: "2"
4
+
5
+ exclude_patterns:
6
+ - "benchmarks/"
7
+ - "examples/"
8
+ - "spec/"
9
+
10
+ plugins:
11
+ rubocop:
12
+ enabled: true
@@ -0,0 +1,10 @@
1
+ ---
2
+ name: "⚠️ Please don't ask for support via issues"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
@@ -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
@@ -1,6 +1,4 @@
1
- --backtrace
2
1
  --color
3
- --format progress
2
+ --require spec_helper
4
3
  --order random
5
- --profile
6
- --warnings
4
+
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
- * Including equalizer module with same keys multiple times won't cause duped keys in `inspect` output (radar)
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
 
@@ -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 [discuss.dry-rb.org](https://discuss.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.
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 [discuss.dry-rb.org](http://discuss.dry-rb.org) instead.
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 [discuss.dry-rb.org](https://discuss.dry-rb.org).
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 do
12
- gem "codeclimate-test-reporter", require: false
13
- gem 'simplecov', require: false
14
- end
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
- Copyright (c) 2009-2013 Dan Kubb
2
- Copyright (c) 2012 Markus Schirp (packaging)
1
+ The MIT License (MIT)
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining
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
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
- # dry-equalizer <a href="https://gitter.im/dry-rb/chat" target="_blank">![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)</a>
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](http://img.shields.io/travis/dry-rb/dry-equalizer.svg)][travis]
7
- [![Maintainability](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/maintainability)](https://codeclimate.com/github/dry-rb/dry-equalizer/maintainability)
8
- [![Test Coverage](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/test_coverage)](https://codeclimate.com/github/dry-rb/dry-equalizer/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
- ``` ruby
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
- * MRI 2.2+
53
- * JRuby 9.x
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
- * Dan Kubb ([dkubb](https://github.com/dkubb))
75
- * Piotr Solnica ([solnic](https://github.com/solnic))
76
- * Markus Schirp ([mbj](https://github.com/mbj))
77
- * Erik Michaels-Ober ([sferik](https://github.com/sferik))
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 &copy; 2009-2013 Dan Kubb. See LICENSE for details.
@@ -0,0 +1,86 @@
1
+ ---
2
+ title: Introduction &amp; 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
+
@@ -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/dryrb/dry-equalizer'
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.0.0'
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.send(:include, Methods)
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
- keys = @keys
75
- define_method(:hash) do | |
76
- keys.map(&method(:send)).push(self.class).hash
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 # module Methods
126
- end # class Equalizer
141
+ end
142
+ end
127
143
  end
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Equalizer < Module
3
3
  # Gem version
4
- VERSION = '0.2.1'.freeze
5
- end # class Equalizer
4
+ VERSION = '0.3.0'.freeze
5
+ end
6
6
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,7 @@
1
- if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
2
- require 'yaml'
3
- rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
4
- latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
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.send(:include, subject)
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.send(:include, subject)
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.send(:include, subject)
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.2.1
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: 2018-04-26 00:00:00.000000000 Z
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/dryrb/dry-equalizer
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.0.0
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
- rubyforge_project:
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