Class: WellCombinationsValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- WellCombinationsValidator
- Includes:
- HasFilters
- Defined in:
- app/validators/well_combinations_validator.rb
Overview
Validator for well combinations Validates the combinations of Wells
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ WellCombinationsValidator
constructor
A new instance of WellCombinationsValidator.
- #valid_combinations ⇒ Array
- #validate(record) ⇒ Object
Methods included from HasFilters
#exclude_marked_for_destruction
Constructor Details
#initialize(options) ⇒ WellCombinationsValidator
Returns a new instance of WellCombinationsValidator.
13 14 15 16 |
# File 'app/validators/well_combinations_validator.rb', line 13 def initialize() super @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'app/validators/well_combinations_validator.rb', line 8 def @options end |
Instance Method Details
#valid_combinations ⇒ Array
20 21 22 |
# File 'app/validators/well_combinations_validator.rb', line 20 def valid_combinations @valid_combinations ||= [:valid_combinations] end |
#validate(record) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/validators/well_combinations_validator.rb', line 25 def validate(record) well_positions = filtered(record.wells).collect(&:position) return if valid_combinations.include?(well_positions) record.errors.add(:wells, "must be in a valid order, currently #{well_positions.join(',')}") end |