Class: Grape::Validations::ContractScope::Validator
- Inherits:
-
Validators::Base
- Object
- Validators::Base
- 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.
Attributes inherited from Validators::Base
Instance Method Summary collapse
-
#initialize(_attrs, _options, _required, _scope, opts) ⇒ Validator
constructor
A new instance of Validator.
-
#validate(request) ⇒ void
Validates a given request.
Methods inherited from Validators::Base
#fail_fast?, inherited, #message, #options_key?, #validate!
Constructor Details
#initialize(_attrs, _options, _required, _scope, opts) ⇒ Validator
Returns a new instance of Validator.
36 37 38 39 |
# File 'lib/grape/validations/contract_scope.rb', line 36 def initialize(_attrs, , _required, _scope, opts) super @schema = opts.fetch(: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
#validate(request) ⇒ void
This method returns an undefined value.
Validates a given request.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/grape/validations/contract_scope.rb', line 45 def validate(request) res = schema.call(request.params) if res.success? request.params.deep_merge!(res.to_h) return end raise Grape::Exceptions::ValidationArrayErrors.new((res.errors.)) end |