Module: Xenon::Routing::PathDirectives

Includes:
RouteDirectives
Included in:
Directives
Defined in:
lib/xenon/routing/path_directives.rb

Instance Method Summary collapse

Methods included from RouteDirectives

#complete, #extract, #extract_request, #fail, #map_request, #map_response, #reject

Instance Method Details

#path(pattern) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/xenon/routing/path_directives.rb', line 27

def path(pattern)
  path_prefix(pattern) do |*captures|
    path_end do
      yield *captures
    end
  end
end

#path_endObject



21
22
23
24
25
# File 'lib/xenon/routing/path_directives.rb', line 21

def path_end
  path_prefix(/\Z/) do
    yield
  end
end

#path_prefix(pattern) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/xenon/routing/path_directives.rb', line 8

def path_prefix(pattern)
  extract_request do |request|
    match = request.unmatched_path.match(pattern)
    if match && match.pre_match == ''
      map_request unmatched_path: match.post_match do
        yield *match.captures
      end
    else
      reject nil # path rejections are nil to allow more specific rejections to be seen
    end
  end
end