Sha256: 7dfbc8b2a62c292e60a5366a4560cf3e6cdc56d9d35734d42a7dfb266cdae398
Contents?: true
Size: 751 Bytes
Versions: 5
Compression:
Stored size: 751 Bytes
Contents
class ExcludesCombinationsValidation < Validation 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 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 end
Version data entries
5 entries across 5 versions & 1 rubygems