Class: Grape::Validations::ContractScope
- Inherits:
-
Object
- Object
- Grape::Validations::ContractScope
- Defined in:
- lib/grape/validations/contract_scope.rb
Instance Method Summary collapse
-
#initialize(api, contract = nil) { ... } ⇒ ContractScope
constructor
Declare the contract to be used for the endpoint's parameters.
Constructor Details
#initialize(api, contract = nil) { ... } ⇒ ContractScope
Declare the contract to be used for the endpoint's parameters.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grape/validations/contract_scope.rb', line 10 def initialize(api, contract = nil, &block) # When block is passed, the first arg is either schema or nil. declared = block ? Dry::Schema.Params(parent: contract, &block) : contract if declared.respond_to?(:schema) # It's a Dry::Validation::Contract, then. schema = declared.new key_map = schema.schema.key_map else # Dry::Schema::Processor, hopefully. schema = declared key_map = declared.key_map end api.inheritable_setting.add_contract_key_map(key_map) api.inheritable_setting.add_validation(Validators::ContractScopeValidator.new(schema:)) end |