Sha256: 40870e79033679179160a7d1ebdb8856eba90aceaac12689e8f838eb5116a3ae
Contents?: true
Size: 1.09 KB
Versions: 17
Compression:
Stored size: 1.09 KB
Contents
module RoutingFilter class Filter attr_accessor :next, :previous, :options def initialize(options = {}) @options = options end def run(method, *args, &block) _next = self.next ? proc {|path, env| self.next.run(method, *args, &block) } : block RoutingFilter.active? ? send(method, *args, &_next) : _next.call(*args) end def run_reverse(method, *args, &block) _prev = previous ? lambda { previous.run_reverse(method, *args, &block) } : block RoutingFilter.active? ? send(method, *args, &_prev) : _prev.call(*args) end protected def extract_segment!(pattern, path) path.sub!(pattern) { $2 || '' } path.replace('/') if path.empty? $1 end def prepend_segment!(result, segment) url = result.is_a?(Array) ? result.first : result url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{segment}#{$2 == '/' ? '' : $2}" } end def append_segment!(result, segment) url = result.is_a?(Array) ? result.first : result url.sub!(%r(/?($|\?))) { "/#{segment}#{$1}" } end end end
Version data entries
17 entries across 17 versions & 4 rubygems