Class: ZohoHub::Validations::ValidatePicklist

Inherits:
BaseValidation show all
Defined in:
lib/zoho_hub/validations/validate_picklist.rb

Instance Attribute Summary

Attributes inherited from BaseValidation

#field, #record

Instance Method Summary collapse

Methods inherited from BaseValidation

#initialize

Constructor Details

This class inherits a constructor from ZohoHub::Validations::BaseValidation

Instance Method Details

#validate(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zoho_hub/validations/validate_picklist.rb', line 8

def validate(options = {})
  value = record.send(field)

  return unless value

  list = options[:list].map { |option| option[:actual_value] }

  return if list.include?(value)

  msg = "has an invalid value `#{value}`. Accepted values: #{list.join(', ')}"
  record.add_error(field, msg)
end