Sha256: 6fb64ec3804fc68bff16e4f0c37731a9014854800a51dc475f5c27daf6d4ca59
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require "active_support/all" require "grape" module Grape module ExtraValidators class MaximumValue < Grape::Validations::Base # ------------------------------------------------------------------------------------------------------------------------ # Methods # ------------------------------------------------------------------------------------------------------------------------ # Public Methods # ------------------------------------------------------------------------------------------------------------------------ def validate_param!(attr_name, params) return if !@required && params[attr_name].blank? maximum_value = @option.instance_of?(Proc) ? @option.call(params) : @option return if maximum_value.blank? value = params[attr_name].to_i return if value <= maximum_value message = "must be equal to or below #{maximum_value}" fail Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grape-extra_validators-2.0.0 | lib/grape/extra_validators/maximum_value.rb |