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

Version Path
routing-filter-0.6.3 lib/routing_filter/filter.rb
routing-filter-0.6.2 lib/routing_filter/filter.rb
routing-filter-0.6.1 lib/routing_filter/filter.rb
routing-filter-0.6.0 lib/routing_filter/filter.rb
routing-filter-0.5.1 lib/routing_filter/filter.rb
routing-filter-0.4.0.1 lib/routing_filter/filter.rb
routing-filter-0.4.0 lib/routing_filter/filter.rb
routing-filter-0.5.0 lib/routing_filter/filter.rb
routing-filter-0.4.0.pre lib/routing_filter/filter.rb
routing-filter-0.3.1 lib/routing_filter/filter.rb
routing-filter-0.3.0 lib/routing_filter/filter.rb
routing-filter-0.3.0.beta lib/routing_filter/filter.rb
routing-filter-0.2.4 lib/routing_filter/filter.rb
sayso-routing-filter-0.2.2.001 lib/routing_filter/filter.rb
vigetlabs-routing-filter-0.2.4 lib/routing_filter/filter.rb
aratak-routing-filter-0.2.4 lib/routing_filter/filter.rb
routing-filter-0.2.3 lib/routing_filter/filter.rb