@@ -8,9 +8,9 @@ module Validations
8
8
# All validators must inherit from this class.
9
9
#
10
10
class Validator
11
- def initialize ( attrs , options , doc_attrs )
11
+ def initialize ( attrs , options , required )
12
12
@attrs = Array ( attrs )
13
- @doc_attrs = doc_attrs
13
+ @required = required
14
14
15
15
if options . is_a? ( Hash ) && !options . empty?
16
16
raise "unknown options: #{ options . keys } "
@@ -19,7 +19,7 @@ def initialize(attrs, options, doc_attrs)
19
19
20
20
def validate! ( params )
21
21
@attrs . each do |attr_name |
22
- if @doc_attrs [ : required] || params . has_key? ( attr_name )
22
+ if @required || params . has_key? ( attr_name )
23
23
validate_param! ( attr_name , params )
24
24
end
25
25
end
@@ -40,7 +40,7 @@ def self.convert_to_short_name(klass)
40
40
##
41
41
# Base class for all validators taking only one param.
42
42
class SingleOptionValidator < Validator
43
- def initialize ( attrs , options , doc_attrs )
43
+ def initialize ( attrs , options , required )
44
44
@option = options
45
45
super
46
46
end
@@ -130,7 +130,7 @@ def validates(attrs, validations)
130
130
def validate ( type , options , attrs , doc_attrs )
131
131
validator_class = Validations ::validators [ type . to_s ]
132
132
if validator_class
133
- @api . settings [ :validations ] << validator_class . new ( attrs , options , doc_attrs )
133
+ @api . settings [ :validations ] << validator_class . new ( attrs , options , doc_attrs [ :required ] )
134
134
else
135
135
raise "unknown validator: #{ type } "
136
136
end
0 commit comments