Class: PipelineValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PipelineValidator
- Defined in:
- app/validators/pipeline_validator.rb
Overview
Validates that attribute belongs to the configured pipeline Requires that the associated attribute responds to
Instance Method Summary collapse
-
#initialize(options) ⇒ PipelineValidator
constructor
A new instance of PipelineValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ PipelineValidator
Returns a new instance of PipelineValidator.
8 9 10 11 12 13 14 |
# File 'app/validators/pipeline_validator.rb', line 8 def initialize() super # We'll give some helpful errors if we configure it wrong raise ArgumentError, 'No target pipeline specified' if expected.nil? raise ArgumentError, "#{expected} is not a recognised pipeline" unless valid_pipeline? end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/validators/pipeline_validator.rb', line 16 def validate_each(record, attribute, value) return if value.blank? actual = value.pipeline return if actual == expected.to_s record.errors.add(attribute, :pipeline_invalid, expected:, actual:) end |