Sha256: 858c0cb8530187be0031b3b8d530393dc15a62a9e491cbe8c1a52cd75e6f73d5

Contents?: true

Size: 1.76 KB

Versions: 5

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.set_starts(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

5 entries across 5 versions & 1 rubygems

Version Path
pacer-1.3.1-java lib/pacer/filter/future_filter.rb
pacer-1.2.0-java lib/pacer/filter/future_filter.rb
pacer-1.1.1-java lib/pacer/filter/future_filter.rb
pacer-1.1.0-java lib/pacer/filter/future_filter.rb
pacer-1.0.3-java lib/pacer/filter/future_filter.rb