Sha256: 76d639e7bcaa89143170e4126c5ef8d15bf2be6519390b682ee66e7bbeaaed5e

Contents?: true

Size: 1.63 KB

Versions: 31

Compression:

Stored size: 1.63 KB

Contents

module Pacer
  module Wrappers
    class PathWrappingPipeFunction
      include com.tinkerpop.pipes.PipeFunction

      attr_reader :block, :graph, :wrapper

      def initialize(back, block)
        @block = block
        if back
          @graph = back.graph
        end
        @wrapper = WrapperSelector.build graph
      end

      def arity
        block.arity
      end

      def compute(path)
        if path.first.is_a? Pacer::Wrappers::ElementWrapper
          block.call path
        else
          p = path.map do |element|
            wrapper.new graph, element
          end
          block.call p
        end
      end

      alias call compute

      def call_with_args(element, *args)
        if path.first.is_a? Pacer::Wrappers::ElementWrapper
          block.call path, *args
        else
          p = path.map do |element|
            wrapper.new graph, element
          end
          block.call p, *args
        end
      end
    end

    class PathUnwrappingPipeFunction
      include com.tinkerpop.pipes.PipeFunction

      attr_reader :block

      def initialize(block)
        @block = block
      end

      def arity
        block.arity
      end

      def compute(path)
        unwrap block.call path
      end

      alias call compute

      def call_with_args(path, *args)
        unwrap block.call path, *args
      end

      def unwrap(p)
        if p.is_a? Array
          p.map do |e|
            if e.is_a? ElementWrapper
              e.element
            else
              e
            end
          end
        elsif p.is_a? ElementWrapper
          p.element
        else
          p
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

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