Class: Committee::Middleware::Base
- Inherits:
-
Object
- Object
- Committee::Middleware::Base
show all
- Defined in:
- lib/committee/middleware/base.rb
Class Method Summary
collapse
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
|
# File 'lib/committee/middleware/base.rb', line 3
def initialize(app, options={})
@app = app
@error_class = options.fetch(:error_class, Committee::ValidationError)
@raise = options[:raise]
@schema = self.class.get_schema(options)
@router = @schema.build_router(options)
end
|
Class Method Details
.get_schema(options) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/committee/middleware/base.rb', line 25
def get_schema(options)
schema = options[:schema]
unless schema
schema = Committee::Drivers::load_from_file(options[:schema_path]) if options[:schema_path]
raise(ArgumentError, "Committee: need option `schema` or `schema_path`") unless schema
end
if !schema.is_a?(Committee::Drivers::Schema)
raise ArgumentError, "Committee: schema expected to be an instance of Committee::Drivers::Schema."
end
return schema
end
|
Instance Method Details
#call(env) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/committee/middleware/base.rb', line 14
def call(env)
request = Rack::Request.new(env)
if @router.includes_request?(request)
handle(request)
else
@app.call(request.env)
end
end
|