Class: WellPositionsValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- WellPositionsValidator
- Includes:
- HasFilters
- Defined in:
- app/validators/well_positions_validator.rb
Overview
Validator to check the correct wells are being used Validates the positions of Wells
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ WellPositionsValidator
constructor
A new instance of WellPositionsValidator.
- #valid_positions ⇒ Array
- #validate(record) ⇒ Object
Methods included from HasFilters
#exclude_marked_for_destruction
Constructor Details
#initialize(options) ⇒ WellPositionsValidator
Returns a new instance of WellPositionsValidator.
13 14 15 16 |
# File 'app/validators/well_positions_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_positions_validator.rb', line 8 def @options end |
Instance Method Details
#valid_positions ⇒ Array
20 21 22 |
# File 'app/validators/well_positions_validator.rb', line 20 def valid_positions @valid_positions ||= [:valid_positions] end |
#validate(record) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/validators/well_positions_validator.rb', line 25 def validate(record) well_positions = filtered(record.wells).collect(&:position) invalid_positions = (well_positions - valid_positions) return if invalid_positions.empty? invalid_wells = invalid_positions.join(',') valid_wells = valid_positions.join(',') record.errors.add(:wells, "#{invalid_wells} must be in positions #{valid_wells}") end |