Class: ExcludesCombinationsValidation

Inherits:
Validation
  • Object
show all
Defined in:
lib/yodel/models/core/validations/excludes_combinations_validation.rb

Instance Attribute Summary

Attributes inherited from Validation

#field, #params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Validation

#initialize, #to_json

Constructor Details

This class inherits a constructor from Validation

Class Method Details

.validate(params, field, name, value, record, errors) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/yodel/models/core/validations/excludes_combinations_validation.rb', line 2

def self.validate(params, field, name, value, record, errors)
  combinations = params['combinations']
  combinations.each do |excluded_combination|
    fail = excluded_combination.all? {|prohibited| value.include?(prohibited)}
    (errors[field.name] << new(combinations)) and return if fail
  end
end

Instance Method Details

#describeObject



10
11
12
13
14
15
16
17
# File 'lib/yodel/models/core/validations/excludes_combinations_validation.rb', line 10

def describe
  if params.size > 1
    combinations = params.collect.with_index {|combo, index| "#{index + 1}. #{combo.to_sentence}"}
  else
    combinations = [params.first.to_sentence]
  end
  "may not contain #{combinations.size == 1 ? 'this' : 'these'} combination#{'s' if combinations.size > 1}: #{combinations.to_sentence(two_words_connector: ', and ')}"
end