Class: Grape::Validations::PresenceValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/validations/validators/presence.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

convert_to_short_name, inherited, #initialize, #message, #options_key?, #validate

Constructor Details

This class inherits a constructor from Grape::Validations::Base

Instance Method Details

#validate!(params) ⇒ Object



4
5
6
7
# File 'lib/grape/validations/validators/presence.rb', line 4

def validate!(params)
  return unless @scope.should_validate?(params)
  super
end

#validate_param!(attr_name, params) ⇒ Object



9
10
11
12
# File 'lib/grape/validations/validators/presence.rb', line 9

def validate_param!(attr_name, params)
  return if params.respond_to?(:key?) && params.key?(attr_name)
  fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:presence)
end