Sha256: 4959e76c162c1514a279d20919ae1196f153344a22a2cd308a9fe645f54641d4

Contents?: true

Size: 1.67 KB

Versions: 13

Compression:

Stored size: 1.67 KB

Contents

module Pacer
  module Neo4j
    module Algo
      class BlockPathExpander
        import org.neo4j.graphdb.PathExpander
        import com.tinkerpop.pipes.Pipe

        include PathExpander
        attr_reader :block, :rev, :graph, :max_depth

        def initialize(block, rev, graph, max_depth)
          @block = block
          @rev = rev
          @graph = graph
          @max_depth = max_depth
        end

        def expand(path, state)
          path = PathWrapper.new(path, graph)
          if max_depth and path.length >= max_depth
            result = []
          else
            result = block.call path, state
          end
          pipe = Pacer::Pipes::NakedPipe.new
          pipe.set_starts result_to_enumerable(result)
          pipe
        end

        def reverse
          BlockPathExpander.new rev, block, graph, max_depth
        end

        def result_to_enumerable(result)
          case result
          when PathWrapper
            fail "Don't just return the arguments in your expander, return edges!"
          when Pacer::Route
            if result.element_type == :edge
              result.pipe.starts
            else
              fail "Expander must return edges"
            end
          when Pacer::Wrappers::EdgeWrapper
            Pacer::Pipes::EnumerablePipe.new [result]
          when Pacer::Pipes::WrappingPipe
            result.starts
          when Pipe
            result
          when Enumerable
            Pacer::Pipes::EnumerablePipe.new result
          when nil
            Pacer::Pipes::EnumerablePipe.new []
          else
            fail "Can't figure out what to do with #{ result.class }"
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pacer-neo4j-2.3.7-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.6-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.5-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.4-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.3-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.2-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.3.0.pre-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.2.0-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.1.5-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.1.4-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.1.2-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.1.1-java lib/pacer-neo4j/algo/block_path_expander.rb
pacer-neo4j-2.1.0-java lib/pacer-neo4j/algo/block_path_expander.rb