Class: Grape::Validations::OneofCollector

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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.



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

def initialize
  @inheritable_setting = Grape::Util::InheritableSetting.new
  @inheritable_setting.do_not_document!
end

Instance Attribute Details

#inheritable_settingObject (readonly)

Returns the value of attribute inheritable_setting.



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

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.



28
29
30
31
32
# File 'lib/grape/validations/oneof_collector.rb', line 28

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

Instance Method Details

#configurationObject



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

def configuration
  nil
end