Skip to content

Commit

Permalink
Merge pull request #98 from dry-rb/92-deprecate-eql-predicate
Browse files Browse the repository at this point in the history
Deprecate eql? in favor of is_eql?
  • Loading branch information
solnic authored Oct 10, 2022
2 parents 894d0fb + 54a9940 commit 796c4f4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
13 changes: 8 additions & 5 deletions lib/dry/logic/predicates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Logic
module Predicates
# rubocop:disable Metrics/ModuleLength
module Methods
extend Dry::Core::Deprecations[:dry_logic]

def self.uuid_format(version)
::Regexp.new(<<~FORMAT.chomp, ::Regexp::IGNORECASE)
\\A[0-9A-F]{8}-[0-9A-F]{4}-#{version}[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\z
Expand Down Expand Up @@ -195,18 +197,19 @@ def excludes?(value, input)
!includes?(value, input)
end

def eql?(left, right)
def is_eql?(left, right)
left.eql?(right)
end

def is?(left, right)
left.equal?(right)
end
deprecate :eql?, :is_eql?

def not_eql?(left, right)
!left.eql?(right)
end

def is?(left, right)
left.equal?(right)
end

def true?(value)
value.equal?(true)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/builder/predicate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@
end

describe "compare methods" do
describe :eql? do
let(:expression) { ->(*) { eql?(10) } }
describe :is_eql? do
let(:expression) { ->(*) { is_eql?(10) } }

describe "success" do
it_behaves_like "predicate" do
Expand Down
2 changes: 1 addition & 1 deletion spec/shared/predicates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

let(:attr?) { Dry::Logic::Predicates[:attr?] }

let(:eql?) { Dry::Logic::Predicates[:eql?] }
let(:is_eql?) { Dry::Logic::Predicates[:is_eql?] }

let(:size?) { Dry::Logic::Predicates[:size?] }

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/operations/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe "#call" do
context "with 1-level nesting" do
subject(:operation) do
described_class.new(Dry::Logic::Rule::Predicate.build(eql?).curry(1), id: :compare, keys: [:num])
described_class.new(Dry::Logic::Rule::Predicate.build(is_eql?).curry(1), id: :compare, keys: [:num])
end

it "applies predicate to args extracted from the input" do
Expand All @@ -18,7 +18,7 @@
context "with 2-levels nesting" do
subject(:operation) do
described_class.new(
Dry::Logic::Rule::Predicate.build(eql?), id: :compare, keys: [[:nums, :left], [:nums, :right]]
Dry::Logic::Rule::Predicate.build(is_eql?), id: :compare, keys: [[:nums, :left], [:nums, :right]]
)
end

Expand All @@ -32,7 +32,7 @@

expect(result.to_ast).to eql(
[:failure, [:compare, [:check, [
[[:nums, :left], [:nums, :right]], [:predicate, [:eql?, [[:left, 1], [:right, 2]]]]
[[:nums, :left], [:nums, :right]], [:predicate, [:is_eql?, [[:left, 1], [:right, 2]]]]
]]]]
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "dry/logic/predicates"

RSpec.describe Dry::Logic::Predicates, "#eql?" do
let(:predicate_name) { :eql? }
let(:predicate_name) { :is_eql? }

context "when value is equal to the arg" do
let(:arguments_list) do
Expand Down

0 comments on commit 796c4f4

Please sign in to comment.