Class: Committee::Middleware::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/middleware/base.rb

Direct Known Subclasses

RequestValidation, ResponseValidation, Stub

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/committee/middleware/base.rb', line 3

def initialize(app, options={})
  @app = app

  @error_class = options.fetch(:error_class, Committee::ValidationError)
  @params_key = options[:params_key] || "committee.params"
  @headers_key = options[:headers_key] || "committee.headers"
  @raise = options[:raise]
  @schema = get_schema(options[:schema] ||
    raise(ArgumentError, "Committee: need option `schema`"))

  @router = Committee::Router.new(@schema,
    prefix: options[:prefix]
  )
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/committee/middleware/base.rb', line 18

def call(env)
  request = Rack::Request.new(env)

  if @router.includes_request?(request)
    handle(request)
  else
    @app.call(request.env)
  end
end