Class: Grape::Validations::ContractScope::Validator
- Inherits:
-
Object
- Object
- Grape::Validations::ContractScope::Validator
- Defined in:
- lib/grape/validations/contract_scope.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #fail_fast? ⇒ Boolean
-
#initialize(*_args, schema:) ⇒ Validator
constructor
A new instance of Validator.
-
#validate(request) ⇒ void
Validates a given request.
Constructor Details
#initialize(*_args, schema:) ⇒ Validator
Returns a new instance of Validator.
36 37 38 |
# File 'lib/grape/validations/contract_scope.rb', line 36 def initialize(*_args, schema:) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
34 35 36 |
# File 'lib/grape/validations/contract_scope.rb', line 34 def schema @schema end |
Instance Method Details
#fail_fast? ⇒ Boolean
65 66 67 |
# File 'lib/grape/validations/contract_scope.rb', line 65 def fail_fast? false end |
#validate(request) ⇒ void
This method returns an undefined value.
Validates a given request.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/grape/validations/contract_scope.rb', line 44 def validate(request) res = schema.call(request.params) if res.success? request.params.deep_merge!(res.to_h) return end errors = [] res.errors..each do || full_name = .path.first.to_s full_name += "[#{.path[1..].join('][')}]" if .path.size > 1 errors << Grape::Exceptions::Validation.new(params: [full_name], message: .text) end raise Grape::Exceptions::ValidationArrayErrors.new(errors) end |