4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/subvalid/validators/in_validator.rb', line 4
def self.validate(object, validation_result=ValidationResult.new, *args)
options = args.to_h rescue args
within = nil
message = "is not included in the list"
case options
when Hash
within = options.fetch(:within)
message = options[:message] || message
when Array
within = options
else
raise "don't know what to do with #{options}"
end
validation_result.add_error(message) unless within.include?(object)
end
|