class Committee::SchemaValidator::HyperSchema::Router
Public Class Methods
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 7 def initialize(schema, validator_option) @prefix = validator_option.prefix @prefix_regexp = /\A#{Regexp.escape(@prefix)}/.freeze if @prefix @schema = schema @validator_option = validator_option end
Public Instance Methods
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 40 def build_schema_validator(request) Committee::SchemaValidator::HyperSchema.new(self, request, @validator_option) end
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 23 def find_link(method, path) path = path.gsub(@prefix_regexp, "") if @prefix link_with_matches = (@schema.routes[method] || []).map do |pattern, link| if matches = pattern.match(path) # prefer path which has fewer matches (eg. `/pets/dog` than `/pets/{uuid}` for path `/pets/dog` ) [matches.captures.size, link, Hash[matches.names.zip(matches.captures)]] else nil end end.compact.sort_by(&:first).first link_with_matches.nil? ? nil : link_with_matches.slice(1, 2) end
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 36 def find_request_link(request) find_link(request.request_method, request.path_info) end
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 15 def includes?(path) !@prefix || path =~ @prefix_regexp end
Source
# File lib/committee/schema_validator/hyper_schema/router.rb, line 19 def includes_request?(request) includes?(request.path) end