Skip to content

Commit a9a0fb2

Browse files
committed
Eliminate runtime .is_a? check from HasValidators
1 parent 246b4fd commit a9a0fb2

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

lib/graphql/schema/member/has_validators.rb

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,38 @@ def validates(validation_config)
1818

1919
# @return [Array<GraphQL::Schema::Validator>]
2020
def validators
21-
own_validators = @own_validators || EMPTY_ARRAY
22-
if self.is_a?(Class) && superclass.respond_to?(:validators) && (inherited_validators = superclass.validators).any?
23-
inherited_validators + own_validators
24-
else
25-
own_validators
21+
@own_validators || EMPTY_ARRAY
22+
end
23+
24+
module ClassConfigured
25+
def inherited(child_cls)
26+
super
27+
child_cls.extend(ClassValidators)
2628
end
29+
30+
module ClassValidators
31+
include Schema::FindInheritedValue::EmptyObjects
32+
33+
def validators
34+
inherited_validators = superclass.validators
35+
if inherited_validators.any?
36+
if @own_validators.nil?
37+
inherited_validators
38+
else
39+
inherited_validators + @own_validators
40+
end
41+
elsif @own_validators.nil?
42+
EMPTY_ARRAY
43+
else
44+
@own_validators
45+
end
46+
end
47+
end
48+
end
49+
50+
def self.extended(child_cls)
51+
super
52+
child_cls.extend(ClassConfigured)
2753
end
2854
end
2955
end

0 commit comments

Comments
 (0)