diff --git a/config/errors.yml b/config/errors.yml index 65f88e9..9f3afd8 100644 --- a/config/errors.yml +++ b/config/errors.yml @@ -20,6 +20,8 @@ en: eql?: "must be equal to %{left}" + is_eql?: "must be equal to %{left}" + not_eql?: "must not be equal to %{left}" filled?: "must be filled" @@ -89,6 +91,8 @@ en: respond_to?: "must respond to %{method}" + interface?: "must respond to %{method}" + size?: arg: default: "size must be %{size}" diff --git a/docsite/source/basics/built-in-predicates.html.md b/docsite/source/basics/built-in-predicates.html.md index 9a49d89..6d3ff36 100644 --- a/docsite/source/basics/built-in-predicates.html.md +++ b/docsite/source/basics/built-in-predicates.html.md @@ -38,7 +38,7 @@ Checks that a key's value is equal to the given value. describe 'eql?' do let(:schema) do Dry::Schema.Params do - required(:sample).value(eql?: 1234) + required(:sample).value(is_eql?: 1234) end end diff --git a/lib/dry/schema/predicate.rb b/lib/dry/schema/predicate.rb index c59965f..70e138b 100644 --- a/lib/dry/schema/predicate.rb +++ b/lib/dry/schema/predicate.rb @@ -71,7 +71,7 @@ module Dry # @api private def ensure_valid - if compiler.predicates[name].arity - 1 != args.size + if compiler.predicates[name].arity - 1 != args.size && !name.eql?(:eql?) raise ArgumentError, "#{name} predicate arity is invalid" end end diff --git a/lib/dry/schema/type_container.rb b/lib/dry/schema/type_container.rb index 98af232..beec3a3 100644 --- a/lib/dry/schema/type_container.rb +++ b/lib/dry/schema/type_container.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "dry/container" -require "dry/types" - module Dry module Schema # A class to build containers for custom types, which can be used in schemas @@ -13,9 +10,9 @@ module Dry # # @api public class TypeContainer - include Dry::Container::Mixin + include Core::Container::Mixin - def initialize(types_container = Dry::Types.container) + def initialize(types_container = ::Dry::Types.container) super() merge(types_container) diff --git a/spec/fixtures/messages.yml b/spec/fixtures/messages.yml index 94342a3..e678100 100644 --- a/spec/fixtures/messages.yml +++ b/spec/fixtures/messages.yml @@ -1,6 +1,6 @@ en: dry_schema: errors: - eql?: + is_eql?: failure: '%{right} is not equal to blue' hint: 'must be equal to blue' diff --git a/spec/integration/hints_spec.rb b/spec/integration/hints_spec.rb index b0ce984..2970868 100644 --- a/spec/integration/hints_spec.rb +++ b/spec/integration/hints_spec.rb @@ -70,10 +70,10 @@ RSpec.describe "Validation hints" do context "with a nested schema with same rule names" do subject(:schema) do Dry::Schema.define do - required(:code).filled(:str?, eql?: "foo") + required(:code).filled(:str?, is_eql?: "foo") required(:nested).hash do - required(:code).filled(:str?, eql?: "bar") + required(:code).filled(:str?, is_eql?: "bar") end end end @@ -150,7 +150,7 @@ RSpec.describe "Validation hints" do Dry::Schema.define do configure { |c| c.messages.load_paths << SPEC_ROOT.join("fixtures/messages.yml") } - required(:pill).filled(eql?: "blue") + required(:pill).filled(is_eql?: "blue") end end diff --git a/spec/integration/message_compiler_spec.rb b/spec/integration/message_compiler_spec.rb index cdc6bd2..f4775b9 100644 --- a/spec/integration/message_compiler_spec.rb +++ b/spec/integration/message_compiler_spec.rb @@ -406,10 +406,10 @@ RSpec.describe Dry::Schema::MessageCompiler do end end - describe ":eql?" do + describe ":is_eql?" do it "returns valid message" do msg = message_compiler.visit( - [:failure, [:str, [:key, [:str, p(:eql?, "Bar", "Foo")]]]] + [:failure, [:str, [:key, [:str, p(:is_eql?, "Bar", "Foo")]]]] ) expect(msg).to eql("must be equal to Bar") diff --git a/spec/integration/params/predicates/eql_spec.rb b/spec/integration/params/predicates/eql_spec.rb index b7dd477..9477439 100644 --- a/spec/integration/params/predicates/eql_spec.rb +++ b/spec/integration/params/predicates/eql_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "Predicates: Eql" do context "with required" do subject(:schema) do Dry::Schema.Params do - required(:foo).value(:string) { eql?("23") } + required(:foo).value(:string) { is_eql?("23") } end end @@ -86,7 +86,7 @@ RSpec.describe "Predicates: Eql" do context "with value" do subject(:schema) do Dry::Schema.Params do - required(:foo).value(:string, eql?: "23") + required(:foo).value(:string, is_eql?: "23") end end @@ -166,7 +166,7 @@ RSpec.describe "Predicates: Eql" do context "with maybe" do subject(:schema) do Dry::Schema.Params do - required(:foo).maybe(:string, eql?: "23") + required(:foo).maybe(:string, is_eql?: "23") end end @@ -248,7 +248,7 @@ RSpec.describe "Predicates: Eql" do context "with filled" do subject(:schema) do Dry::Schema.Params do - optional(:foo).filled(:string, eql?: "23") + optional(:foo).filled(:string, is_eql?: "23") end end diff --git a/spec/integration/schema/custom_types_spec.rb b/spec/integration/schema/custom_types_spec.rb index 172b31e..5e5c36a 100644 --- a/spec/integration/schema/custom_types_spec.rb +++ b/spec/integration/schema/custom_types_spec.rb @@ -46,7 +46,7 @@ RSpec.describe "Registering custom types" do end it "raises exception that nothing is registered with the key" do - expect { result }.to raise_exception(Dry::Container::KeyError) + expect { result }.to raise_exception(Dry::Core::Container::KeyError) end end @@ -123,7 +123,7 @@ RSpec.describe "Registering custom types" do end it "raises exception that nothing is registered with the key" do - expect { result }.to raise_exception(Dry::Container::KeyError) + expect { result }.to raise_exception(Dry::Core::Container::KeyError) end end diff --git a/spec/integration/schema/predicates/eql_spec.rb b/spec/integration/schema/predicates/eql_spec.rb index 864eb24..1d863e6 100644 --- a/spec/integration/schema/predicates/eql_spec.rb +++ b/spec/integration/schema/predicates/eql_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "Predicates: Eql" do context "with required" do subject(:schema) do Dry::Schema.define do - required(:foo) { eql?(23) } + required(:foo) { is_eql?(23) } end end @@ -44,7 +44,7 @@ RSpec.describe "Predicates: Eql" do context "with optional" do subject(:schema) do Dry::Schema.define do - optional(:foo) { eql?(23) } + optional(:foo) { is_eql?(23) } end end @@ -86,7 +86,7 @@ RSpec.describe "Predicates: Eql" do context "with value" do subject(:schema) do Dry::Schema.define do - required(:foo).value(eql?: 23) + required(:foo).value(is_eql?: 23) end end @@ -126,7 +126,7 @@ RSpec.describe "Predicates: Eql" do context "with filled" do subject(:schema) do Dry::Schema.define do - required(:foo).filled(eql?: 23) + required(:foo).filled(is_eql?: 23) end end @@ -166,7 +166,7 @@ RSpec.describe "Predicates: Eql" do context "with maybe" do subject(:schema) do Dry::Schema.define do - required(:foo).maybe(eql?: 23) + required(:foo).maybe(is_eql?: 23) end end @@ -208,7 +208,7 @@ RSpec.describe "Predicates: Eql" do context "with value" do subject(:schema) do Dry::Schema.define do - optional(:foo).value(eql?: 23) + optional(:foo).value(is_eql?: 23) end end @@ -248,7 +248,7 @@ RSpec.describe "Predicates: Eql" do context "with filled" do subject(:schema) do Dry::Schema.define do - optional(:foo).filled(eql?: 23) + optional(:foo).filled(is_eql?: 23) end end @@ -288,7 +288,7 @@ RSpec.describe "Predicates: Eql" do context "with maybe" do subject(:schema) do Dry::Schema.define do - optional(:foo).maybe(eql?: 23) + optional(:foo).maybe(is_eql?: 23) end end diff --git a/spec/integration/schema/predicates/respond_to_spec.rb b/spec/integration/schema/predicates/respond_to_spec.rb index dc07a0a..cd15016 100644 --- a/spec/integration/schema/predicates/respond_to_spec.rb +++ b/spec/integration/schema/predicates/respond_to_spec.rb @@ -97,7 +97,7 @@ RSpec.describe "Predicates: Respond To" do context "with required" do context "with value" do subject(:schema) do - Dry::Schema.define { required(:foo).value(respond_to?: :bar) } + Dry::Schema.define { required(:foo).value(interface?: :bar) } end context "with valid input" do @@ -143,7 +143,7 @@ RSpec.describe "Predicates: Respond To" do context "with filled" do subject(:schema) do - Dry::Schema.define { required(:foo).filled(respond_to?: :bar) } + Dry::Schema.define { required(:foo).filled(interface?: :bar) } end context "with valid input" do @@ -189,7 +189,7 @@ RSpec.describe "Predicates: Respond To" do context "with maybe" do subject(:schema) do - Dry::Schema.define { required(:foo).maybe(respond_to?: :bar) } + Dry::Schema.define { required(:foo).maybe(interface?: :bar) } end context "with valid input" do @@ -237,7 +237,7 @@ RSpec.describe "Predicates: Respond To" do context "with optional" do context "with value" do subject(:schema) do - Dry::Schema.define { optional(:foo).value(respond_to?: :bar) } + Dry::Schema.define { optional(:foo).value(interface?: :bar) } end context "with valid input" do @@ -283,7 +283,7 @@ RSpec.describe "Predicates: Respond To" do context "with filled" do subject(:schema) do - Dry::Schema.define { optional(:foo).filled(respond_to?: :bar) } + Dry::Schema.define { optional(:foo).filled(interface?: :bar) } end context "with valid input" do @@ -329,7 +329,7 @@ RSpec.describe "Predicates: Respond To" do context "with maybe" do subject(:schema) do - Dry::Schema.define { optional(:foo).maybe(respond_to?: :bar) } + Dry::Schema.define { optional(:foo).maybe(interface?: :bar) } end context "with valid input" do diff --git a/spec/integration/type_inheritance_spec.rb b/spec/integration/type_inheritance_spec.rb index 5f0991e..d20c7b4 100644 --- a/spec/integration/type_inheritance_spec.rb +++ b/spec/integration/type_inheritance_spec.rb @@ -50,25 +50,25 @@ RSpec.describe "inheriting from a parent and extending its rules" do end required(:qux).hash do required(:hello).hash do - required(:wow).value(:string, eql?: "a") - required(:such).value(:string, eql?: "cool") + required(:wow).value(:string, is_eql?: "a") + required(:such).value(:string, is_eql?: "cool") required(:amaze).value(array[:string], size?: 1) end required(:my).hash do - required(:wow).value(:string, eql?: "b") - required(:such).value(:string, eql?: "cool") + required(:wow).value(:string, is_eql?: "b") + required(:such).value(:string, is_eql?: "cool") required(:amaze).value(array[:string], size?: 1) end required(:friend).hash do - required(:wow).filled(:string, eql?: "c") - required(:such).filled(:string, eql?: "cool") + required(:wow).filled(:string, is_eql?: "c") + required(:such).filled(:string, is_eql?: "cool") required(:amaze).value(array[:string], size?: 1) end end end required(:last).filled.hash do - required(:not).value(:array, eql?: ["rad"]) - required(:least).value(:string, eql?: "done") + required(:not).value(:array, is_eql?: ["rad"]) + required(:least).value(:string, is_eql?: "done") end end end diff --git a/spec/unit/dry/schema/trace_spec.rb b/spec/unit/dry/schema/trace_spec.rb index 7278efd..7d46fd1 100644 --- a/spec/unit/dry/schema/trace_spec.rb +++ b/spec/unit/dry/schema/trace_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Dry::Schema::Trace do end it "stores evaluated predicates with args" do - trace.evaluate(eql?: "foo") + trace.evaluate(is_eql?: "foo") expect(trace.captures).to include(trace.eql?("foo")) end @@ -23,7 +23,7 @@ RSpec.describe Dry::Schema::Trace do it "creates predicate objects" do predicate = trace.eql?("foo") - expect(predicate.name).to be(:eql?) + expect(predicate.name).to be(:is_eql?) expect(predicate.args).to eql(["foo"]) end