Class: IncludesCombinationsValidation

Inherits:
Validation
  • Object
show all
Defined in:
lib/yodel/models/core/validations/includes_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/includes_combinations_validation.rb', line 2

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

Instance Method Details

#describeObject



10
11
12
13
# File 'lib/yodel/models/core/validations/includes_combinations_validation.rb', line 10

def describe
  combinations = params.collect(&:to_s).join(', ')
  "must contain one of these combinations: #{combinations}"
end