Class: Rack::App::Middlewares::Params::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/app/middlewares/params/definition.rb

Instance Method Summary collapse

Constructor Details

#initialize(&descriptor) ⇒ Definition

Returns a new instance of Definition.



4
5
6
7
8
# File 'lib/rack/app/middlewares/params/definition.rb', line 4

def initialize(&descriptor)
  @required = {}
  @optional = {}
  instance_exec(&descriptor)
end

Instance Method Details

#optional(params_key, options) ⇒ Object



14
15
16
# File 'lib/rack/app/middlewares/params/definition.rb', line 14

def optional(params_key, options)
  @optional[params_key.to_s] = self.class::Options.new(options).formatted
end

#required(params_key, options) ⇒ Object



10
11
12
# File 'lib/rack/app/middlewares/params/definition.rb', line 10

def required(params_key, options)
  @required[params_key.to_s] = self.class::Options.new(options).formatted
end

#to_descriptorObject



18
19
20
# File 'lib/rack/app/middlewares/params/definition.rb', line 18

def to_descriptor
  { :required => @required, :optional => @optional }
end