Class: Committee::Router

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

Instance Method Summary collapse

Constructor Details

#initialize(schema, options = {}) ⇒ Router

Returns a new instance of Router.



3
4
5
6
7
# File 'lib/committee/router.rb', line 3

def initialize(schema, options = {})
  @routes = build_routes(schema)
  @prefix = options[:prefix]
  @prefix_regexp = /\A#{Regexp.escape(@prefix)}/.freeze if @prefix
end

Instance Method Details



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/committee/router.rb', line 17

def find_link(method, path)
  path = path.gsub(@prefix_regexp, "") if @prefix
  if method_routes = @routes[method]
    method_routes.each do |pattern, link|
      if path =~ pattern
        return link
      end
    end
  end
  nil
end


29
30
31
# File 'lib/committee/router.rb', line 29

def find_request_link(request)
  find_link(request.request_method, request.path_info)
end

#includes?(path) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/committee/router.rb', line 9

def includes?(path)
  !@prefix || path =~ @prefix_regexp
end

#includes_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/committee/router.rb', line 13

def includes_request?(request)
  includes?(request.path)
end