class Hippa::Enum::Validators::MultipleValidator
Public Class Methods
kind()
click to toggle source
# File lib/hippa/enum/validators/multiple_validator.rb, line 23 def self.kind :custom end
Public Instance Methods
add_error_message(record, attribute)
click to toggle source
# File lib/hippa/enum/validators/multiple_validator.rb, line 15 def add_error_message(record, attribute) record.errors[attribute] << (options[:message] || "is not in #{options[:in].join ", "}") end
all_included?(values, allowed)
click to toggle source
# File lib/hippa/enum/validators/multiple_validator.rb, line 19 def all_included?(values, allowed) (values - allowed).empty? end
validate_each(record, attribute, values)
click to toggle source
# File lib/hippa/enum/validators/multiple_validator.rb, line 5 def validate_each(record, attribute, values) values = Array(values) if options[:allow_nil] add_error_message record, attribute if !all_included?(values, options[:in]) else add_error_message record, attribute if values.empty? || !all_included?(values, options[:in]) end end