Class: Grape::Validations::OneofCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/validations/oneof_collector.rb

Overview

Stand-in for the @api object that ParamsScope normally writes to. Used when evaluating a single variant block of a oneof: schema so that the variant’s validators are captured locally rather than registered on the real API. Exposes only the slice of the API surface that ParamsScope and its helpers touch during definition.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOneofCollector

Returns a new instance of OneofCollector.



13
14
15
16
# File 'lib/grape/validations/oneof_collector.rb', line 13

def initialize
  @inheritable_setting = Grape::Util::InheritableSetting.new
  @inheritable_setting.namespace_inheritable[:do_not_document] = true
end

Instance Attribute Details

#inheritable_settingObject (readonly)

Returns the value of attribute inheritable_setting.



11
12
13
# File 'lib/grape/validations/oneof_collector.rb', line 11

def inheritable_setting
  @inheritable_setting
end

Class Method Details

.collect(variant_block) ⇒ Object

Evaluate variant_block in a fresh ParamsScope backed by a new collector and return the validators that the block registered.



32
33
34
35
36
# File 'lib/grape/validations/oneof_collector.rb', line 32

def self.collect(variant_block)
  collector = new
  ParamsScope.new(api: collector, type: Hash, &variant_block)
  collector.validators
end

Instance Method Details

#configurationObject



18
19
20
# File 'lib/grape/validations/oneof_collector.rb', line 18

def configuration
  nil
end

#declared_paramsObject



26
27
28
# File 'lib/grape/validations/oneof_collector.rb', line 26

def declared_params
  inheritable_setting.namespace_stackable[:declared_params]
end

#validatorsObject



22
23
24
# File 'lib/grape/validations/oneof_collector.rb', line 22

def validators
  inheritable_setting.namespace_stackable[:validations]
end