Module: Grape::DSL::Validations::ClassMethods
- Defined in:
- lib/grape/dsl/validations.rb
Instance Method Summary collapse
-
#contract(contract = nil) { ... } ⇒ Object
Declare the contract to be used for the endpoint’s parameters.
-
#params { ... } ⇒ Object
Opens a root-level ParamsScope, defining parameter coercions and validations for the endpoint.
-
#reset_validations! ⇒ Object
Clears all defined parameters and validations.
Instance Method Details
#contract(contract = nil) { ... } ⇒ Object
Declare the contract to be used for the endpoint’s parameters.
48 49 50 51 52 53 |
# File 'lib/grape/dsl/validations.rb', line 48 def contract(contract = nil, &block) raise ArgumentError, 'Either contract or block must be provided' unless contract || block raise ArgumentError, 'Cannot inherit from contract, only schema' if block && contract.respond_to?(:schema) Grape::Validations::ContractScope.new(self, contract, &block) end |
#params { ... } ⇒ Object
Opens a root-level ParamsScope, defining parameter coercions and validations for the endpoint.
38 39 40 |
# File 'lib/grape/dsl/validations.rb', line 38 def params(&block) Grape::Validations::ParamsScope.new(api: self, type: Hash, &block) end |
#reset_validations! ⇒ Object
Clears all defined parameters and validations. The main purpose of it is to clean up settings, so next endpoint won’t interfere with previous one.
params do
# params for the endpoint below this block
end
post '/current' do
# whatever
end
# somewhere between them the reset_validations! method gets called
params do
# params for the endpoint below this block
end
post '/next' do
# whatever
end
29 30 31 32 33 |
# File 'lib/grape/dsl/validations.rb', line 29 def reset_validations! unset_namespace_stackable :declared_params unset_namespace_stackable :validations unset_namespace_stackable :params end |