Class: WeakParameters::ListValidator
Instance Attribute Summary collapse
#block, #controller, #options
Instance Method Summary
collapse
#key, #required?, #strong?, #type
Constructor Details
#initialize(controller, key, validator, options) ⇒ ListValidator
4
5
6
7
|
# File 'lib/weak_parameters/list_validator.rb', line 4
def initialize(controller, key, validator, options)
super controller, key, options
@validator = validator
end
|
Instance Attribute Details
#validator ⇒ Object
Returns the value of attribute validator.
3
4
5
|
# File 'lib/weak_parameters/list_validator.rb', line 3
def validator
@validator
end
|
Instance Method Details
#strong_params(*args) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/weak_parameters/list_validator.rb', line 19
def strong_params(*args)
super
return {} unless exist?
strong_values = value.map.with_index do |_, i|
validator.strong_params(*path, i)[i]
end.compact
strong_values.present? ? { key => strong_values } : {}
end
|
#validate(*args) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/weak_parameters/list_validator.rb', line 9
def validate(*args)
super
if valid? && exist?
value.each.with_index do |_, i|
validator.validate(*path, i)
end
end
end
|
#validators ⇒ Object
29
30
31
|
# File 'lib/weak_parameters/list_validator.rb', line 29
def validators
[ validator ]
end
|