File: allow_blank.rb

package info (click to toggle)
ruby-grape 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,032 kB
  • sloc: ruby: 24,329; makefile: 6
file content (18 lines) | stat: -rw-r--r-- 525 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module Grape
  module Validations
    class AllowBlankValidator < Base
      def validate_param!(attr_name, params)
        return if (options_key?(:value) ? @option[:value] : @option) || !params.is_a?(Hash)

        value = params[attr_name]
        value = value.strip if value.respond_to?(:strip)

        return if value == false || value.present?

        raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:blank))
      end
    end
  end
end