Module: Roda::RodaPlugins::OptimizedSegmentMatchers::RequestMethods

Defined in:
lib/roda/plugins/optimized_segment_matchers.rb

Instance Method Summary collapse

Instance Method Details

#is_segmentObject

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



46
47
48
49
50
51
52
53
54
# File 'lib/roda/plugins/optimized_segment_matchers.rb', line 46

def is_segment
  rp = @remaining_path
  if rp.getbyte(0) == 47 && !rp.index('/', 1) && (len = rp.length) > 1
    always do
      @remaining_path = ""
      yield rp[1, len]
    end
  end
end

#on_segmentObject

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/roda/plugins/optimized_segment_matchers.rb', line 26

def on_segment
  rp = @remaining_path
  if rp.getbyte(0) == 47
    if last = rp.index('/', 1)
      return false if last == 1
      always do
        @remaining_path = rp[last, rp.length]
        yield rp[1, last-1]
      end
    elsif (len = rp.length) > 1
      always do
        @remaining_path = ""
        yield rp[1, len]
      end
    end
  end
end