Class: GroongaClientModel::Validations::TypeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/groonga_client_model/validations/type_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/groonga_client_model/validations/type_validator.rb', line 20

def validate_each(record, attribute, value)
  column = record.class.columns[attribute]
  return if column.nil?
  value_type = column["value_type"]
  return if value_type.nil?

  case value_type["name"]
  when "UInt8"
    validate_uint(record, attribute, value, 8)
  when "UInt16"
    validate_uint(record, attribute, value, 16)
  when "UInt32"
    validate_uint(record, attribute, value, 32)
  when "UInt64"
    validate_uint(record, attribute, value, 64)
  when "Int8"
    validate_int(record, attribute, value, 8)
  when "Int16"
    validate_int(record, attribute, value, 16)
  when "Int32"
    validate_int(record, attribute, value, 32)
  when "Int64"
    validate_int(record, attribute, value, 64)
  when "Float"
    validate_float(record, attribute, value)
  when "Time"
    validate_time(record, attribute, value)
  end
end