dry-equalizer 0.2.2 → 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: 68e7a5819b71d2ffd60f4424d3b06e92710404a1a83b5fb1770f36530fee537e
4
- data.tar.gz: fbaa5d489d993948159108249b42eaec44a144163ea73285cff6c88c0cec1dd0
3
+ metadata.gz: 9e167f2f667d5c3e4bf962263e4285d327c9e29aacc650c4f70debbeb1af29df
4
+ data.tar.gz: 55c6c4b07d8a4474070bfe4a964ef29f8725ba7798c3abf4e40e82db48b4eea6
5
5
  SHA512:
6
- metadata.gz: 7951e751feca649d17457d9d95f18af296bac9a583ed5d3644edb9e926afcdd2187af0effec08723a580b3acadd9fbac3467bda3c90ef5863c417c14b1d9e22b
7
- data.tar.gz: e09afaa53dcb1d775a634d453f3e3d9b015834a3d07e2ae3cfb2bedcb0cf9b37825da42e3cf8224f926c81eafd195d6b981700a2586c9e609bc9d37da331cf1f
6
+ metadata.gz: 998bd2189807358dd8d1b44e30d9eb8cd634e908f7a51be3a6151af18d41a2333c3abac36f4781cec9008c55904cd890d96659cfd2a0b2eb1580d3c2af82b8dd
7
+ data.tar.gz: 7b8a7f6f5840ba503f4574b4f279f73641632ee0faf8eab8c57db44e9ceda51a7fef200112dc59dffff7a7d1fcc7e11ba8eba9951a2d0023437b935903692e25
@@ -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
+
@@ -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
@@ -1,8 +1,25 @@
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
+
1
18
  # v0.2.2 2019-03-08
2
19
 
3
20
  ### Added
4
21
 
5
- * Generation of `#to_s` and `#inspect` can be disabled with `inspect: false` (flash-gordon)
22
+ - Generation of `#to_s` and `#inspect` can be disabled with `inspect: false` (flash-gordon)
6
23
  ```ruby
7
24
  class User
8
25
  include Dry::Equalizer(:id, :name, :age, inspect: false)
@@ -15,7 +32,7 @@
15
32
 
16
33
  ### Fixed
17
34
 
18
- * 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)
19
36
 
20
37
  [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-equalizer/compare/v0.2.0...v0.2.1)
21
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)
@@ -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
@@ -9,8 +9,9 @@ group :development, :test do
9
9
  end
10
10
 
11
11
  group :test do
12
- platform :mri do
13
- gem "codeclimate-test-reporter", require: false
14
- gem 'simplecov', require: false
15
- 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
16
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,20 +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
- [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]
13
14
 
14
- Examples
15
- --------
15
+ ## Examples
16
16
 
17
- ``` ruby
17
+ ```ruby
18
18
  class GeoLocation
19
19
  include Dry::Equalizer(:latitude, :longitude)
20
20
 
@@ -42,14 +42,13 @@ point_a.eql?(point_c) # => false
42
42
  point_a.equal?(point_c) # => false
43
43
  ```
44
44
 
45
- Supported Ruby Versions
46
- -----------------------
45
+ ## Supported Ruby Versions
47
46
 
48
47
  This library aims to support and is [tested against][travis] the following Ruby
49
48
  implementations:
50
49
 
51
- * MRI 2.2+
52
- * JRuby 9.x
50
+ - MRI 2.4+
51
+ - JRuby 9.x
53
52
 
54
53
  If something doesn't work on one of these versions, it's a bug.
55
54
 
@@ -65,22 +64,19 @@ patches in a timely fashion. If critical issues for a particular implementation
65
64
  exist at the time of a major release, support for that Ruby version may be
66
65
  dropped.
67
66
 
68
- Credits
69
- -------
67
+ ## Credits
70
68
 
71
69
  This is a fork of the original [equalizer](https://github.com/dkubb/equalizer).
72
70
 
73
- * Dan Kubb ([dkubb](https://github.com/dkubb))
74
- * Piotr Solnica ([solnic](https://github.com/solnic))
75
- * Markus Schirp ([mbj](https://github.com/mbj))
76
- * 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))
77
75
 
78
- Contributing
79
- -------------
76
+ ## Contributing
80
77
 
81
78
  See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
82
79
 
83
- Copyright
84
- ---------
80
+ ## Copyright
85
81
 
86
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,5 +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'
18
+ gem.required_ruby_version = '>= 2.4.0'
19
19
  end
@@ -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, inspect: true)
24
+ def initialize(*keys, **options)
22
25
  @keys = keys.uniq
23
- define_methods(inspect: inspect)
26
+ define_methods(**options)
24
27
  freeze
25
28
  end
26
29
 
@@ -36,17 +39,20 @@ 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(inspect: true)
53
+ def define_methods(inspect: true, immutable: false)
48
54
  define_cmp_method
49
- define_hash_method
55
+ define_hash_method(immutable: immutable)
50
56
  define_inspect_method if inspect
51
57
  end
52
58
 
@@ -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.2'.freeze
5
- end # class Equalizer
4
+ VERSION = '0.3.0'.freeze
5
+ end
6
6
  end
@@ -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
 
@@ -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)
@@ -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
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.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Kubb
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-09 00:00:00.000000000 Z
12
+ date: 2019-11-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Module to define equality, equivalence and inspection methods
15
15
  email:
@@ -22,17 +22,24 @@ extra_rdoc_files:
22
22
  - README.md
23
23
  - CONTRIBUTING.md
24
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"
25
31
  - ".gitignore"
26
32
  - ".rspec"
27
33
  - ".rubocop.yml"
28
- - ".travis.yml"
29
34
  - ".yardstick.yml"
30
35
  - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
31
37
  - CONTRIBUTING.md
32
38
  - Gemfile
33
39
  - LICENSE
34
40
  - README.md
35
41
  - Rakefile
42
+ - docsite/source/index.html.md
36
43
  - dry-equalizer.gemspec
37
44
  - lib/dry-equalizer.rb
38
45
  - lib/dry/equalizer.rb
@@ -43,7 +50,7 @@ files:
43
50
  - spec/unit/equalizer/methods/eql_predicate_spec.rb
44
51
  - spec/unit/equalizer/methods/equality_operator_spec.rb
45
52
  - spec/unit/equalizer/universal_spec.rb
46
- homepage: https://github.com/dryrb/dry-equalizer
53
+ homepage: https://github.com/dry-rb/dry-equalizer
47
54
  licenses:
48
55
  - MIT
49
56
  metadata: {}
@@ -55,14 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
62
  requirements:
56
63
  - - ">="
57
64
  - !ruby/object:Gem::Version
58
- version: 2.0.0
65
+ version: 2.4.0
59
66
  required_rubygems_version: !ruby/object:Gem::Requirement
60
67
  requirements:
61
68
  - - ">="
62
69
  - !ruby/object:Gem::Version
63
70
  version: '0'
64
71
  requirements: []
65
- rubygems_version: 3.0.3
72
+ rubygems_version: 3.0.6
66
73
  signing_key:
67
74
  specification_version: 4
68
75
  summary: Module to define equality, equivalence and inspection methods
@@ -1,24 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without benchmarks tools
4
- after_success:
5
- - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
6
- rvm:
7
- - 2.2.10
8
- - 2.3.8
9
- - 2.4.5
10
- - 2.5.3
11
- - 2.6.1
12
- - jruby-9.2.6.0
13
- env:
14
- global:
15
- - COVERAGE=true
16
- - JRUBY_OPTS='--dev -J-Xmx1024M'
17
- notifications:
18
- email: false
19
- webhooks:
20
- urls:
21
- - https://webhooks.gitter.im/e/19098b4253a72c9796db
22
- on_success: change # options: [always|never|change] default: always
23
- on_failure: always # options: [always|never|change] default: always
24
- on_start: false # default: false