2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Validations
|
|
|
|
module Validators
|
|
|
|
class Limit < Grape::Validations::Base
|
|
|
|
def validate_param!(attr_name, params)
|
|
|
|
value = params[attr_name]
|
|
|
|
|
2022-04-04 20:08:12 -04:00
|
|
|
return if value.nil? || value.size <= @option
|
2020-04-21 11:21:10 -04:00
|
|
|
|
2020-12-10 07:09:43 -05:00
|
|
|
raise Grape::Exceptions::Validation.new(
|
2020-04-21 11:21:10 -04:00
|
|
|
params: [@scope.full_name(attr_name)],
|
|
|
|
message: "#{@scope.full_name(attr_name)} must be less than #{@option} characters"
|
2020-12-10 07:09:43 -05:00
|
|
|
)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|