File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module Schema
7
7
# @api private
8
8
class Trace < ::BasicObject
9
9
INVALID_PREDICATES = %i[ key? ] . freeze
10
+ RESPOND_TO_MISSING_METHOD = ::Kernel . instance_method ( :respond_to_missing? )
10
11
11
12
include ::Dry ::Equalizer ( :compiler , :captures )
12
13
@@ -86,12 +87,13 @@ def reduced_rule
86
87
end
87
88
88
89
def respond_to_missing? ( meth , include_private = false )
89
- super || ( meth . to_s . end_with? ( QUESTION_MARK ) && compuiler . support? ( meth ) )
90
+ RESPOND_TO_MISSING_METHOD . bind_call ( self , meth , include_private ) ||
91
+ ( meth . to_s . end_with? ( QUESTION_MARK ) && compiler . support? ( meth ) )
90
92
end
91
93
92
94
# @api private
93
95
def method_missing ( meth , *args , &block )
94
- if meth . to_s . end_with? ( QUESTION_MARK )
96
+ if ! meth . equal? ( :respond_to_missing? ) && meth . to_s . end_with? ( QUESTION_MARK )
95
97
if ::Dry ::Schema ::Trace ::INVALID_PREDICATES . include? ( meth )
96
98
::Kernel . raise InvalidSchemaError , "#{ meth } predicate cannot be used in this context"
97
99
end
Original file line number Diff line number Diff line change 31
31
expect { trace . not_here } . to raise_error ( NoMethodError , /not_here/ )
32
32
end
33
33
end
34
+
35
+ describe "#respond_to?" do
36
+ let ( :respond_to ) do
37
+ Kernel . instance_method ( :respond_to? )
38
+ end
39
+
40
+ it "returns true for predicates" do
41
+ expect ( respond_to . bind_call ( trace , :eql? ) ) . to be ( true )
42
+ end
43
+
44
+ it "returns false for other methods" do
45
+ expect ( respond_to . bind_call ( trace , :not_here? ) ) . to be ( false )
46
+ end
47
+ end
34
48
end
You can’t perform that action at this time.
0 commit comments