class Committee::Middleware::Base
Public Class Methods
Source
# File lib/committee/middleware/base.rb, line 31 def get_schema(options) schema = options[:schema] if !schema && options[:schema_path] # In the future, we could have `parser_options` as an exposed config? parser_options = options.key?(:strict_reference_validation) ? { strict_reference_validation: options[:strict_reference_validation] } : {} schema = Committee::Drivers::load_from_file(options[:schema_path], parser_options: parser_options) end raise(ArgumentError, "Committee: need option `schema` or `schema_path`") unless schema # Expect the type we want by now. If we don't have it, the user passed # something else non-standard in. if !schema.is_a?(Committee::Drivers::Schema) raise ArgumentError, "Committee: schema expected to be an instance of Committee::Drivers::Schema." end return schema end
Source
# File lib/committee/middleware/base.rb, line 6 def initialize(app, options = {}) @app = app @error_class = options.fetch(:error_class, Committee::ValidationError) @error_handler = options[:error_handler] @ignore_error = options.fetch(:ignore_error, false) @raise = options[:raise] @schema = self.class.get_schema(options) @router = @schema.build_router(options) @accept_request_filter = options[:accept_request_filter] || ->(_) { true } end
Public Instance Methods
Source
# File lib/committee/middleware/base.rb, line 20 def call(env) request = Rack::Request.new(env) if @router.includes_request?(request) && @accept_request_filter.call(request) handle(request) else @app.call(request.env) end end
Private Instance Methods
Source
# File lib/committee/middleware/base.rb, line 52 def build_schema_validator(request) @router.build_schema_validator(request) end