Class: ComponentValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ComponentValidator
- Defined in:
- lib/decidim/component_validator.rb
Overview
A custom validator to make sure components are correctly assigned to a model.
Adds a presence validation and checks that the manifest is the correct one.
Instance Method Summary collapse
-
#check_validity! ⇒ Object
Validates the arguments passed to the validator.
-
#validate_each(record, attribute, component) ⇒ Object
The actual validator method.
Instance Method Details
#check_validity! ⇒ Object
Validates the arguments passed to the validator.
8 9 10 |
# File 'lib/decidim/component_validator.rb', line 8 def check_validity! raise ArgumentError, "You must include a `manifest` option with the name of the manifest to validate when validating a component" if [:manifest].blank? end |
#validate_each(record, attribute, component) ⇒ Object
The actual validator method. It is called when ActiveRecord iterates over all the validators.
14 15 16 17 18 19 20 21 |
# File 'lib/decidim/component_validator.rb', line 14 def validate_each(record, attribute, component) unless component record.errors.add(attribute, :blank) return end record.errors.add(attribute, :invalid) if component.manifest_name.to_s != [:manifest].to_s end |