module Roda::RodaPlugins::OptimizedSegmentMatchers::RequestMethods

  1. lib/roda/plugins/optimized_segment_matchers.rb

Methods

Public Instance

  1. is_segment
  2. on_segment

Public Instance methods

is_segment()

Optimized version of +r.is String+ that yields the next segment only if it is the final segment.

[show source]
   # File lib/roda/plugins/optimized_segment_matchers.rb
41 def is_segment
42   rp = @remaining_path
43   if rp.getbyte(0) == 47 && !rp.index('/', 1) && (len = rp.length) > 1
44     @remaining_path = ""
45     always{yield rp[1, len]}
46   end
47 end
on_segment()

Optimized version of +r.on String+ that yields the next segment if there is a segment.

[show source]
   # File lib/roda/plugins/optimized_segment_matchers.rb
26 def on_segment
27   rp = @remaining_path
28   if rp.getbyte(0) == 47
29     if last = rp.index('/', 1)
30       @remaining_path = rp[last, rp.length]
31       always{yield rp[1, last-1]}
32     elsif (len = rp.length) > 1
33       @remaining_path = ""
34       always{yield rp[1, len]}
35     end
36   end
37 end