Method: GraphQL::Schema::Validator::NumericalityValidator#validate

Defined in:
lib/graphql/schema/validator/numericality_validator.rb

#validate(object, context, value) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/graphql/schema/validator/numericality_validator.rb', line 54

def validate(object, context, value)
  if permitted_empty_value?(value)
    # pass in this case
  elsif value.nil? # @allow_null is handled in the parent class
    @null_message
  elsif @greater_than && value <= @greater_than
    partial_format(@message, { comparison: "greater than", target: @greater_than })
  elsif @greater_than_or_equal_to && value < @greater_than_or_equal_to
    partial_format(@message, { comparison: "greater than or equal to", target: @greater_than_or_equal_to })
  elsif @less_than && value >= @less_than
    partial_format(@message, { comparison: "less than", target: @less_than })
  elsif @less_than_or_equal_to && value > @less_than_or_equal_to
    partial_format(@message, { comparison: "less than or equal to", target: @less_than_or_equal_to })
  elsif @equal_to && value != @equal_to
    partial_format(@message, { comparison: "equal to", target: @equal_to })
  elsif @other_than && value == @other_than
    partial_format(@message, { comparison: "something other than", target: @other_than })
  elsif @even && !value.even?
    (partial_format(@message, { comparison: "even", target: "" })).strip
  elsif @odd && !value.odd?
    (partial_format(@message, { comparison: "odd", target: "" })).strip
  elsif @within && !@within.include?(value)
    partial_format(@message, { comparison: "within", target: @within })
  end
end