dry-equalizer-0.3.0/0000755000175000017500000000000013617257532014246 5ustar utkarshutkarshdry-equalizer-0.3.0/CODE_OF_CONDUCT.md0000644000175000017500000000266113617257532017052 0ustar utkarshutkarsh# Contributor Code of Conduct 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. 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. 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. 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. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 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) dry-equalizer-0.3.0/CONTRIBUTING.md0000644000175000017500000000312413617257532016477 0ustar utkarshutkarsh# Issue Guidelines ## Reporting bugs 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. ## Reporting feature requests 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. ## Reporting questions, support requests, ideas, concerns etc. **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead. # Pull Request Guidelines A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc. Other requirements: 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. 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style. 3) Add API documentation if it's a new feature 4) Update API documentation if it changes an existing feature 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 # Asking for help 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). dry-equalizer-0.3.0/.rubocop.yml0000644000175000017500000000241413617257532016521 0ustar utkarshutkarsh# this file is managed by dry-rb/devtools project AllCops: TargetRubyVersion: 2.4 Style/EachWithObject: Enabled: false Style/StringLiterals: Enabled: true EnforcedStyle: single_quotes Style/Alias: Enabled: false Style/LambdaCall: Enabled: false Style/StabbyLambdaParentheses: Enabled: false Style/FormatString: Enabled: false Style/Documentation: Enabled: false Layout/SpaceInLambdaLiteral: Enabled: false Layout/MultilineMethodCallIndentation: Enabled: true EnforcedStyle: indented Metrics/LineLength: Max: 100 Metrics/MethodLength: Max: 22 Metrics/ClassLength: Max: 150 Metrics/AbcSize: Max: 20 Metrics/BlockLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: true Max: 10 Lint/BooleanSymbol: Enabled: false Style/AccessModifierDeclarations: Enabled: false Style/BlockDelimiters: Enabled: false Layout/IndentFirstArrayElement: EnforcedStyle: consistent Style/ClassAndModuleChildren: Exclude: - "spec/**/*_spec.rb" Lint/HandleExceptions: Exclude: - "spec/spec_helper.rb" Naming/FileName: Exclude: - "lib/dry-*.rb" Style/SymbolArray: Exclude: - "spec/**/*_spec.rb" Style/ConditionalAssignment: Enabled: false Naming/MethodName: Enabled: false Style/AsciiComments: Enabled: false dry-equalizer-0.3.0/Rakefile0000644000175000017500000000021413617257532015710 0ustar utkarshutkarshrequire 'bundler' Bundler::GemHelper.install_tasks require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task default: [:spec] dry-equalizer-0.3.0/dry-equalizer.gemspec0000644000175000017500000000141213617257532020406 0ustar utkarshutkarshrequire File.expand_path('../lib/dry/equalizer/version', __FILE__) Gem::Specification.new do |gem| gem.name = 'dry-equalizer' gem.version = Dry::Equalizer::VERSION.dup gem.authors = ['Dan Kubb', 'Markus Schirp'] gem.email = %w[dan.kubb@gmail.com mbj@schirp-dso.com] gem.description = 'Module to define equality, equivalence and inspection methods' gem.summary = gem.description gem.homepage = 'https://github.com/dry-rb/dry-equalizer' gem.licenses = 'MIT' gem.require_paths = %w[lib] gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- spec/{unit,integration}`.split("\n") gem.extra_rdoc_files = %w[LICENSE README.md CONTRIBUTING.md] gem.required_ruby_version = '>= 2.4.0' end dry-equalizer-0.3.0/CHANGELOG.md0000644000175000017500000000245413617257532016064 0ustar utkarshutkarsh# v0.3.0 2019-11-07 ### Changed - [BREAKING] Dropped support for Ruby < 2.4 ### Added - 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) ```ruby class User include Dry::Equalizer(:id, :name, :age, immutable: true) end ``` [Compare v0.2.2...v0.3.0](https://github.com/dry-rb/dry-equalizer/compare/v0.2.2...v0.3.0) # v0.2.2 2019-03-08 ### Added - Generation of `#to_s` and `#inspect` can be disabled with `inspect: false` (flash-gordon) ```ruby class User include Dry::Equalizer(:id, :name, :age, inspect: false) end ``` [Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-equalizer/compare/v0.2.1...v0.2.2) # v0.2.1 2018-04-26 ### Fixed - Including equalizer module with same keys multiple times won't cause duped keys in `inspect` output (radar) [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-equalizer/compare/v0.2.0...v0.2.1) # v0.2.0 2015-11-13 Really make it work with MRI 2.0 again (it's Friday 13th OK?!) # v0.1.1 2015-11-13 Make it work with MRI 2.0 again # v0.1.0 2015-11-11 ## Added - `Dry::Equalizer()` method accepting a list of keys (solnic) ## Changed - `eql?` no longer tries to coerce `other` with `coerce` method (solnic) dry-equalizer-0.3.0/.codeclimate.yml0000644000175000017500000000025013617257532017315 0ustar utkarshutkarsh# this file is managed by dry-rb/devtools project version: "2" exclude_patterns: - "benchmarks/" - "examples/" - "spec/" plugins: rubocop: enabled: true dry-equalizer-0.3.0/.gitignore0000644000175000017500000000042213617257532016234 0ustar utkarshutkarsh## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## Rubinius *.rbc .rbx ## PROJECT::GENERAL *.gem coverage profiling turbulence rdoc pkg tmp doc log .yardoc measurements ## BUNDLER .bundle Gemfile.lock bin bundle ## PROJECT::SPECIFIC dry-equalizer-0.3.0/Gemfile0000644000175000017500000000046313617257532015544 0ustar utkarshutkarshsource 'https://rubygems.org' gemspec group :development, :test do gem 'bundler' gem 'rake' gem 'rspec', '~> 3.5' end group :test do gem 'simplecov', require: false, platform: :mri end group :tools do gem 'ossy', git: 'https://github.com/solnic/ossy.git', branch: 'master', platform: :mri end dry-equalizer-0.3.0/.yardstick.yml0000644000175000017500000000002313617257532017037 0ustar utkarshutkarsh--- threshold: 100 dry-equalizer-0.3.0/README.md0000644000175000017500000000535613617257532015536 0ustar utkarshutkarsh[gem]: https://rubygems.org/gems/dry-equalizer [ci]: https://github.com/dry-rb/dry-equalizer/actions?query=workflow%3Aci [codeclimate]: https://codeclimate.com/github/dry-rb/dry-equalizer [chat]: https://dry-rb.zulipchat.com # dry-equalizer [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat] Module to define equality, equivalence and inspection methods [![Gem Version](http://img.shields.io/gem/v/dry-equalizer.svg)][gem] [![Build Status](https://github.com/dry-rb/dry-equalizer/workflows/ci/badge.svg)][ci] [![Maintainability](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/maintainability)][codeclimate] [![Test Coverage](https://api.codeclimate.com/v1/badges/5a9a139af1d4a80a28c4/test_coverage)][codeclimate] ## Examples ```ruby class GeoLocation include Dry::Equalizer(:latitude, :longitude) attr_reader :latitude, :longitude def initialize(latitude, longitude) @latitude, @longitude = latitude, longitude end end point_a = GeoLocation.new(1, 2) point_b = GeoLocation.new(1, 2) point_c = GeoLocation.new(2, 2) point_a.inspect # => "#" point_a == point_b # => true point_a.hash == point_b.hash # => true point_a.eql?(point_b) # => true point_a.equal?(point_b) # => false point_a == point_c # => false point_a.hash == point_c.hash # => false point_a.eql?(point_c) # => false point_a.equal?(point_c) # => false ``` ## Supported Ruby Versions This library aims to support and is [tested against][travis] the following Ruby implementations: - MRI 2.4+ - JRuby 9.x If something doesn't work on one of these versions, it's a bug. This library may inadvertently work (or seem to work) on other Ruby versions or implementations, however support will only be provided for the implementations listed above. If you would like this library to support another Ruby version or implementation, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped. ## Credits This is a fork of the original [equalizer](https://github.com/dkubb/equalizer). - Dan Kubb ([dkubb](https://github.com/dkubb)) - Piotr Solnica ([solnic](https://github.com/solnic)) - Markus Schirp ([mbj](https://github.com/mbj)) - Erik Michaels-Ober ([sferik](https://github.com/sferik)) ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) for details. ## Copyright Copyright © 2009-2013 Dan Kubb. See LICENSE for details. dry-equalizer-0.3.0/.rspec0000644000175000017500000000005613617257532015364 0ustar utkarshutkarsh--color --require spec_helper --order random dry-equalizer-0.3.0/docsite/0000755000175000017500000000000013617257532015700 5ustar utkarshutkarshdry-equalizer-0.3.0/docsite/source/0000755000175000017500000000000013617257532017200 5ustar utkarshutkarshdry-equalizer-0.3.0/docsite/source/index.html.md0000644000175000017500000000342613617257532021601 0ustar utkarshutkarsh--- title: Introduction & Usage description: Simple mixin providing equality, equivalence and inspection methods layout: gem-single order: 5 type: gem name: dry-equalizer --- `dry-equalizer` is a simple mixin that can be used to add instance variable based equality, equivalence and inspection methods to your objects. ### Usage ```ruby require 'dry-equalizer' class GeoLocation include Dry::Equalizer(:latitude, :longitude) attr_reader :latitude, :longitude def initialize(latitude, longitude) @latitude, @longitude = latitude, longitude end end point_a = GeoLocation.new(1, 2) point_b = GeoLocation.new(1, 2) point_c = GeoLocation.new(2, 2) point_a.inspect # => "#" point_a == point_b # => true point_a.hash == point_b.hash # => true point_a.eql?(point_b) # => true point_a.equal?(point_b) # => false point_a == point_c # => false point_a.hash == point_c.hash # => false point_a.eql?(point_c) # => false point_a.equal?(point_c) # => false ``` ### Configuration options #### `inspect` Use `inspect` option to skip `#inspect` method overloading: ```ruby class Foo include Dry::Equalizer(:a, inspect: false) attr_reader :a, :b def initialize(a, b) @a, @b = a, b end end Foo.new(1, 2).inspect # => "#" ``` #### `immutable` For objects that are immutable it doesn't make sense to calculate `#hash` every time it's called. To memoize hash use `immutable` option: ```ruby class ImmutableHash include Dry::Equalizer(:foo, :bar, immutable: true) attr_accessor :foo, :bar def initialize(foo, bar) @foo, @bar = foo, bar end end obj = ImmutableHash.new('foo', 'bar') old_hash = obj.hash obj.foo = 'changed' old_hash == obj.hash # => true ``` dry-equalizer-0.3.0/LICENSE0000644000175000017500000000207313617257532015255 0ustar utkarshutkarshThe MIT License (MIT) Copyright (c) 2015-2019 dry-rb team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dry-equalizer-0.3.0/spec/0000755000175000017500000000000013617257532015200 5ustar utkarshutkarshdry-equalizer-0.3.0/spec/unit/0000755000175000017500000000000013617257532016157 5ustar utkarshutkarshdry-equalizer-0.3.0/spec/unit/equalizer/0000755000175000017500000000000013617257532020160 5ustar utkarshutkarshdry-equalizer-0.3.0/spec/unit/equalizer/methods/0000755000175000017500000000000013617257532021623 5ustar utkarshutkarshdry-equalizer-0.3.0/spec/unit/equalizer/methods/equality_operator_spec.rb0000644000175000017500000000343113617257532026733 0ustar utkarshutkarshrequire 'spec_helper' RSpec.describe Dry::Equalizer::Methods, '#==' do subject { object == other } let(:object) { described_class.new(true) } let(:described_class) { Class.new(super_class) } let(:super_class) do Class.new do include Dry::Equalizer::Methods attr_reader :boolean def initialize(boolean) @boolean = boolean end def cmp?(comparator, other) boolean.send(comparator, other.boolean) end end end context 'with the same object' do let(:other) { object } it { should be(true) } it 'is symmetric' do should eql(other == object) end end context 'with an equivalent object' do let(:other) { object.dup } it { should be(true) } it 'is symmetric' do should eql(other == object) end end context 'with a subclass instance having equivalent obervable state' do let(:other) { Class.new(described_class).new(true) } it { should be(true) } it 'is not symmetric' do # the subclass instance should maintain substitutability with the object # (in the LSP sense) the reverse is not true. should_not eql(other == object) end end context 'with a superclass instance having equivalent observable state' do let(:other) { super_class.new(true) } it { should be(false) } it 'is not symmetric' do should_not eql(other == object) end end context 'with an object of another class' do let(:other) { Class.new.new } it { should be(false) } it 'is symmetric' do should eql(other == object) end end context 'with a different object' do let(:other) { described_class.new(false) } it { should be(false) } it 'is symmetric' do should eql(other == object) end end end dry-equalizer-0.3.0/spec/unit/equalizer/methods/eql_predicate_spec.rb0000644000175000017500000000226213617257532025765 0ustar utkarshutkarshrequire 'spec_helper' RSpec.describe Dry::Equalizer::Methods, '#eql?' do subject { object.eql?(other) } let(:object) { described_class.new(true) } let(:described_class) do Class.new do include Dry::Equalizer::Methods attr_reader :boolean def initialize(boolean) @boolean = boolean end def cmp?(comparator, other) boolean.send(comparator, other.boolean) end end end context 'with the same object' do let(:other) { object } it { should be(true) } it 'is symmetric' do should eql(other.eql?(object)) end end context 'with an equivalent object' do let(:other) { object.dup } it { should be(true) } it 'is symmetric' do should eql(other.eql?(object)) end end context 'with an equivalent object of a subclass' do let(:other) { Class.new(described_class).new(true) } it { should be(false) } it 'is symmetric' do should eql(other.eql?(object)) end end context 'with a different object' do let(:other) { described_class.new(false) } it { should be(false) } it 'is symmetric' do should eql(other.eql?(object)) end end end dry-equalizer-0.3.0/spec/unit/equalizer/universal_spec.rb0000644000175000017500000001405213617257532023531 0ustar utkarshutkarshrequire 'spec_helper' RSpec.describe Dry::Equalizer do let(:name) { 'User' } let(:klass) { ::Class.new } context 'with no keys' do subject { Dry::Equalizer() } before do # specify the class #name method allow(klass).to receive(:name).and_return(name) klass.include(subject) end let(:instance) { klass.new } it { should be_instance_of(described_class) } it { should be_frozen } it 'defines #hash and #inspect methods dynamically' do expect(subject.public_instance_methods(false).map(&:to_s).sort) .to eql(%w[hash inspect]) end describe '#eql?' do context 'when the objects are similar' do let(:other) { instance.dup } it { expect(instance.eql?(other)).to be(true) } end context 'when the objects are different' do let(:other) { double('other') } it { expect(instance.eql?(other)).to be(false) } end end describe '#==' do context 'when the objects are similar' do let(:other) { instance.dup } it { expect(instance == other).to be(true) } end context 'when the objects are different' do let(:other) { double('other') } it { expect(instance == other).to be(false) } end end describe '#hash' do it 'has the expected arity' do expect(klass.instance_method(:hash).arity).to be(0) end it { expect(instance.hash).to eql([klass].hash) } end describe '#inspect' do it 'has the expected arity' do expect(klass.instance_method(:inspect).arity).to be(0) end it { expect(instance.inspect).to eql('#') } end end context 'with keys' do subject { Dry::Equalizer(*keys) } let(:keys) { %i[firstname lastname].freeze } let(:firstname) { 'John' } let(:lastname) { 'Doe' } let(:instance) { klass.new(firstname, lastname) } let(:klass) do ::Class.new do attr_reader :firstname, :lastname attr_writer :firstname private :firstname, :lastname def initialize(firstname, lastname) @firstname = firstname @lastname = lastname end end end before do # specify the class #inspect method allow(klass).to receive_messages(name: nil, inspect: name) klass.include(subject) end it { should be_instance_of(described_class) } it { should be_frozen } it 'defines #hash and #inspect methods dynamically' do expect(subject.public_instance_methods(false).map(&:to_s).sort) .to eql(%w[hash inspect]) end describe '#eql?' do context 'when the objects are similar' do let(:other) { instance.dup } it { expect(instance.eql?(other)).to be(true) } end context 'when the objects are different' do let(:other) { double('other') } it { expect(instance.eql?(other)).to be(false) } end end describe '#==' do context 'when the objects are similar' do let(:other) { instance.dup } it { expect(instance == other).to be(true) } end context 'when the objects are different type' do let(:other) { klass.new('Foo', 'Bar') } it { expect(instance == other).to be(false) } end context 'when the objects are from different type' do let(:other) { double('other') } it { expect(instance == other).to be(false) } end end describe '#hash' do it 'returns the expected hash' do expect(instance.hash) .to eql([firstname, lastname, klass].hash) end end describe '#inspect' do it 'returns the expected string' do expect(instance.inspect) .to eql('#') end end context 'when immutable' do describe '#hash' do subject { Dry::Equalizer(*keys, immutable: true) } it 'returns memoized hash' do expect { instance.firstname = 'Changed' }.not_to(change { instance.hash }) end context 'when frozen' do it 'returns memoized hash' do instance.freeze expect(instance.hash) .to eql([firstname, lastname, klass].hash) end end end end end context 'with duplicate keys' do subject { Dry::Equalizer(*keys) } let(:keys) { %i[firstname firstname lastname].freeze } let(:firstname) { 'John' } let(:lastname) { 'Doe' } let(:instance) { klass.new(firstname, lastname) } let(:klass) do ::Class.new do attr_reader :firstname, :lastname private :firstname, :lastname def initialize(firstname, lastname) @firstname = firstname @lastname = lastname end end end before do # specify the class #inspect method allow(klass).to receive_messages(name: nil, inspect: name) klass.include(subject) end it { should be_instance_of(described_class) } it { should be_frozen } describe '#inspect' do it 'returns the expected string' do expect(instance.inspect) .to eql('#') end end end context 'with options' do context 'w/o inspect' do subject { Dry::Equalizer(*keys, inspect: false) } let(:keys) { %i[firstname lastname].freeze } let(:firstname) { 'John' } let(:lastname) { 'Doe' } let(:instance) { klass.new(firstname, lastname) } let(:klass) do ::Struct.new(:firstname, :lastname) end before { klass.include(subject) } describe '#inspect' do it 'returns the default string' do expect(instance.inspect).to eql('#') expect(instance.to_s).to eql('#') end end end end end dry-equalizer-0.3.0/spec/unit/equalizer/included_spec.rb0000644000175000017500000000312413617257532023306 0ustar utkarshutkarshrequire 'spec_helper' RSpec.describe Dry::Equalizer, '#included' do subject { descendant.instance_exec(object) { |mod| include mod } } let(:object) { described_class.new } let(:descendant) { Class.new } let(:superclass) { described_class.superclass } before do # Prevent Module.included from being called through inheritance allow(described_class::Methods).to receive(:included) end around do |example| # Restore included method after each example superclass.class_eval do alias_method :original_included, :included example.call undef_method :included alias_method :included, :original_included end end it 'delegates to the superclass #included method' do # This is the most succinct approach I could think of to test whether the # superclass#included method is called. All of the built-in rspec helpers # did not seem to work for this. included = false superclass.class_eval do define_method(:included) do |_| # Only set the flag when an Dry::Equalizer instance is included. # Otherwise, other module includes (which get triggered internally # in RSpec when `change` is used for the first time, since it uses # autoloading for its matchers) will wrongly set this flag. included = true if self.kind_of?(Dry::Equalizer) end end expect { subject }.to change { included }.from(false).to(true) end it 'includes methods into the descendant' do subject expect(descendant.included_modules).to include(described_class::Methods) end end dry-equalizer-0.3.0/spec/spec_helper.rb0000644000175000017500000000053613617257532020022 0ustar utkarshutkarshif ENV['COVERAGE'] == 'true' require 'simplecov' SimpleCov.start do add_filter '/spec/' end end require 'dry-equalizer' RSpec.configure do |config| config.raise_errors_for_deprecations! config.disable_monkey_patching! config.expect_with :rspec do |expect_with| expect_with.syntax = :expect end config.warnings = true end dry-equalizer-0.3.0/spec/support/0000755000175000017500000000000013617257532016714 5ustar utkarshutkarshdry-equalizer-0.3.0/spec/support/config_alias.rb0000644000175000017500000000010213617257532021650 0ustar utkarshutkarshrequire 'rbconfig' ::Config = RbConfig unless defined?(::Config) dry-equalizer-0.3.0/.github/0000755000175000017500000000000013617257532015606 5ustar utkarshutkarshdry-equalizer-0.3.0/.github/workflows/0000755000175000017500000000000013617257532017643 5ustar utkarshutkarshdry-equalizer-0.3.0/.github/workflows/docsite.yml0000644000175000017500000000152013617257532022016 0ustar utkarshutkarsh# this file is managed by dry-rb/devtools project name: docsite on: push: paths: - docsite/** - .github/workflows/docsite.yml branches: - master - release-** tags: jobs: update-docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Set up Ruby uses: actions/setup-ruby@v1 with: ruby-version: "2.6.x" - name: Install dependencies run: | gem install bundler bundle install --jobs 4 --retry 3 --without benchmarks sql - name: Symlink ossy run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy - name: Trigger dry-rb.org deploy env: GITHUB_LOGIN: dry-bot GITHUB_TOKEN: ${{ secrets.GH_PAT }} run: bin/ossy github workflow dry-rb/dry-rb.org ci dry-equalizer-0.3.0/.github/workflows/sync_configs.yml0000644000175000017500000000200713617257532023051 0ustar utkarshutkarsh# this file is managed by dry-rb/devtools project name: sync_configs on: repository_dispatch: jobs: sync-configs: runs-on: ubuntu-latest if: github.event.action == 'sync_configs' steps: - uses: actions/checkout@v1 - name: Update configuration files from devtools env: GITHUB_LOGIN: dry-bot GITHUB_TOKEN: ${{ secrets.GH_PAT }} run: | git clone https://github.com/dry-rb/devtools.git tmp/devtools if [ -f ".github/workflows/custom_ci.yml" ]; then rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ; else rsync -av tmp/devtools/shared/ . ; fi git config --local user.email "dry-bot@dry-rb.org" git config --local user.name "dry-bot" git add -A git commit -m "[devtools] config sync" || echo "nothing changed" - name: Push changes uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GH_PAT }} dry-equalizer-0.3.0/.github/ISSUE_TEMPLATE/0000755000175000017500000000000013617257532017771 5ustar utkarshutkarshdry-equalizer-0.3.0/.github/ISSUE_TEMPLATE/---bug-report.md0000644000175000017500000000161413617257532022612 0ustar utkarshutkarsh--- name: "\U0001F41B Bug report" about: See CONTRIBUTING.md for more information title: '' labels: bug assignees: '' --- **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS** For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md) **Before you report** :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. **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Provide detailed steps to reproduce, an executable script would be best. **Expected behavior** A clear and concise description of what you expected to happen. **Your environment** - Affects my production application: **YES/NO** - Ruby version: ... - OS: ... dry-equalizer-0.3.0/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md0000644000175000017500000000022613617257532030227 0ustar utkarshutkarsh--- name: "⚠️ Please don't ask for support via issues" about: See CONTRIBUTING.md for more information title: '' labels: '' assignees: '' --- dry-equalizer-0.3.0/.github/ISSUE_TEMPLATE/---feature-request.md0000644000175000017500000000055613617257532023651 0ustar utkarshutkarsh--- name: "\U0001F6E0 Feature request" about: See CONTRIBUTING.md for more information title: '' labels: feature assignees: '' --- Summary of what the feature is supposed to do. ## Examples Code examples showing how the feature could be used. ## Resources Additional information, like a link to the discussion forum thread where the feature was discussed etc. dry-equalizer-0.3.0/lib/0000755000175000017500000000000013617257532015014 5ustar utkarshutkarshdry-equalizer-0.3.0/lib/dry-equalizer.rb0000644000175000017500000000003013617257532020127 0ustar utkarshutkarshrequire 'dry/equalizer' dry-equalizer-0.3.0/lib/dry/0000755000175000017500000000000013617257532015612 5ustar utkarshutkarshdry-equalizer-0.3.0/lib/dry/equalizer.rb0000644000175000017500000000706713617257532020152 0ustar utkarshutkarshmodule Dry # Build an equalizer module for the inclusion in other class # # @api public def self.Equalizer(*keys, **options) Dry::Equalizer.new(*keys, **options) end # Define equality, equivalence and inspection methods class Equalizer < Module # Initialize an Equalizer with the given keys # # Will use the keys with which it is initialized to define #cmp?, # #hash, and #inspect # # @param [Array] keys # @param [Hash] options # @option options [Boolean] :inspect whether to define #inspect method # @option options [Boolean] :immutable whether to memoize #hash method # # @return [undefined] # # @api private def initialize(*keys, **options) @keys = keys.uniq define_methods(**options) freeze end private # Hook called when module is included # # @param [Module] descendant # the module or class including Equalizer # # @return [self] # # @api private def included(descendant) super descendant.include Methods end # Define the equalizer methods based on #keys # # @param [Boolean] inspect whether to define #inspect method # @param [Boolean] immutable whether to memoize #hash method # # @return [undefined] # # @api private def define_methods(inspect: true, immutable: false) define_cmp_method define_hash_method(immutable: immutable) define_inspect_method if inspect end # Define an #cmp? method based on the instance's values identified by #keys # # @return [undefined] # # @api private def define_cmp_method keys = @keys define_method(:cmp?) do |comparator, other| keys.all? do |key| __send__(key).public_send(comparator, other.__send__(key)) end end private :cmp? end # Define a #hash method based on the instance's values identified by #keys # # @return [undefined] # # @api private def define_hash_method(immutable:) calculate_hash = ->(obj) { @keys.map { |key| obj.__send__(key) }.push(obj.class).hash } if immutable define_method(:hash) do @__hash__ ||= calculate_hash.call(self) end define_method(:freeze) do hash super() end else define_method(:hash) do calculate_hash.call(self) end end end # Define an inspect method that reports the values of the instance's keys # # @return [undefined] # # @api private def define_inspect_method keys = @keys define_method(:inspect) do klass = self.class name = klass.name || klass.inspect "#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>" end end # The comparison methods module Methods # Compare the object with other object for equality # # @example # object.eql?(other) # => true or false # # @param [Object] other # the other object to compare with # # @return [Boolean] # # @api public def eql?(other) instance_of?(other.class) && cmp?(__method__, other) end # Compare the object with other object for equivalency # # @example # object == other # => true or false # # @param [Object] other # the other object to compare with # # @return [Boolean] # # @api public def ==(other) other.is_a?(self.class) && cmp?(__method__, other) end end end end dry-equalizer-0.3.0/lib/dry/equalizer/0000755000175000017500000000000013617257532017613 5ustar utkarshutkarshdry-equalizer-0.3.0/lib/dry/equalizer/version.rb0000644000175000017500000000013713617257532021626 0ustar utkarshutkarshmodule Dry class Equalizer < Module # Gem version VERSION = '0.3.0'.freeze end end