Class: Grape::Validations::Validators::SameAsValidator

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

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

#fail_fast?, inherited, #initialize, #message, #options_key?, #validate, #validate!

Constructor Details

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

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/grape/validations/validators/same_as_validator.rb', line 7

def validate_param!(attr_name, params)
  confirmation = options_key?(:value) ? @option[:value] : @option
  return if params[attr_name] == params[confirmation]

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