2020-04-22 19:07:51 +05:30
|
|
|
# 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-06-21 17:19:12 +05:30
|
|
|
return if value.nil? || value.size <= @option
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
raise Grape::Exceptions::Validation.new(
|
2020-04-22 19:07:51 +05:30
|
|
|
params: [@scope.full_name(attr_name)],
|
|
|
|
message: "#{@scope.full_name(attr_name)} must be less than #{@option} characters"
|
2021-02-22 17:27:13 +05:30
|
|
|
)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|