Class: WeakParameters::ObjectValidator
- Inherits:
-
HashValidator
- Object
- BaseValidator
- HashValidator
- WeakParameters::ObjectValidator
- Defined in:
- lib/weak_parameters/object_validator.rb
Instance Attribute Summary collapse
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
Attributes inherited from BaseValidator
Instance Method Summary collapse
-
#initialize(controller, key, validators, options = {}) ⇒ ObjectValidator
constructor
A new instance of ObjectValidator.
- #strong_params(*args) ⇒ Object
- #validate(*args) ⇒ Object
Methods inherited from BaseValidator
#key, #required?, #strong?, #type
Constructor Details
#initialize(controller, key, validators, options = {}) ⇒ ObjectValidator
Returns a new instance of ObjectValidator.
4 5 6 7 |
# File 'lib/weak_parameters/object_validator.rb', line 4 def initialize(controller, key, validators, = {}) super controller, key, @validators = validators end |
Instance Attribute Details
#validators ⇒ Object (readonly)
Returns the value of attribute validators.
3 4 5 |
# File 'lib/weak_parameters/object_validator.rb', line 3 def validators @validators end |
Instance Method Details
#strong_params(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/weak_parameters/object_validator.rb', line 19 def strong_params(*args) super strong_values = validators.map do |validator| validator.strong_params(*path) end.inject(ActionController::Parameters.new, &:merge) return {} if strong_values.blank? { key => strong_values } end |
#validate(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/weak_parameters/object_validator.rb', line 9 def validate(*args) super if valid? && exist? validators.each do |validator| validator.validate(*path) end end end |