Sha256: a9dc3b43dc5d83316f0cf838bc721923b07d13492847ebda8a313637f1aeb296

Contents?: true

Size: 1.76 KB

Versions: 29

Compression:

Stored size: 1.76 KB

Contents

module Pacer
  module Routes
    module RouteOperations
      def lookahead(opts = {}, &block)
        chain_route({ :filter => :future, :block => block }.merge(opts))
      end

      def neg_lookahead(opts = {}, &block)
        chain_route({ :filter => :future, :neg_block => block }.merge(opts))
      end
    end
  end

  module Filter
    module FutureFilter
      import com.tinkerpop.pipes.filter.FutureFilterPipe

      attr_accessor :min, :max

      def block=(block)
        @future_filter = [block, false]
      end

      def neg_block=(block)
        @future_filter = [block, true]
      end

      protected

      def after_initialize
        @future_filter = nil unless defined? @future_filter
        @route = nil unless defined? @route
        super
      end

      def attach_pipe(end_pipe)
        pipe = FutureFilterPipe.new(lookahead_pipe)
        pipe.setStarts(end_pipe) if end_pipe
        pipe
      end

      def lookahead_route
        if @future_filter
          block, negate = @future_filter
          @future_filter = nil
          route = block.call(Pacer::Route.empty(self))
          route = route.back while route.remove_from_lookahead
          route = route.lookahead_replacement.call(route) if route.lookahead_replacement
          if min or max
            route = route.has_count_route(:min => min, :max => max).is(true)
          end
          if negate
            route = route.chain_route(pipe_class: Pacer::Pipes::IsEmptyPipe, :route_name => 'negate')
          end
          @route = route
        elsif @route
          @route
        end
      end

      def lookahead_pipe
        Pacer::Route.pipeline(lookahead_route)
      end

      def inspect_string
        "#{ inspect_class_name }(#{ lookahead_route.inspect })"
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
pacer-2.0.24-java lib/pacer/filter/future_filter.rb
pacer-2.0.22-java lib/pacer/filter/future_filter.rb
pacer-2.0.20-java lib/pacer/filter/future_filter.rb
pacer-2.0.19-java lib/pacer/filter/future_filter.rb
pacer-2.0.18-java lib/pacer/filter/future_filter.rb
pacer-2.0.17-java lib/pacer/filter/future_filter.rb
pacer-2.0.16-java lib/pacer/filter/future_filter.rb
pacer-2.0.15-java lib/pacer/filter/future_filter.rb
pacer-2.0.14-java lib/pacer/filter/future_filter.rb
pacer-2.0.13-java lib/pacer/filter/future_filter.rb
pacer-2.0.12-java lib/pacer/filter/future_filter.rb
pacer-2.0.10-java lib/pacer/filter/future_filter.rb
pacer-2.0.10.pre-java lib/pacer/filter/future_filter.rb
pacer-2.0.8-java lib/pacer/filter/future_filter.rb
pacer-2.0.6-java lib/pacer/filter/future_filter.rb
pacer-2.0.4.pre-java lib/pacer/filter/future_filter.rb
pacer-2.0.0.pre-java lib/pacer/filter/future_filter.rb
pacer-1.6.0-java lib/pacer/filter/future_filter.rb
pacer-1.5.4-java lib/pacer/filter/future_filter.rb
pacer-1.5.3-java lib/pacer/filter/future_filter.rb