Sha256: e5a8aacc1e2c294b4efe78522aa928d7aa8715590c2028591dd92c16922e8b65

Contents?: true

Size: 1.71 KB

Versions: 31

Compression:

Stored size: 1.71 KB

Contents

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

      attr_reader :block, :graph, :wrapper, :extensions

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

      def arity
        block.arity
      end

      def compute(element)
        e = wrapper.new graph, element if element
        block.call e
      end

      alias call compute

      def call_with_args(element, *args)
        e = wrapper.new graph, element if element
        block.call e, *args
      end

      def wrap_path(path)
        path.collect do |item|
          if item.is_a? Pacer::Vertex
            wrapped = Pacer::Wrappers::VertexWrapper.new graph, item
            wrapped
          elsif item.is_a? Pacer::Edge
            wrapped = Pacer::Wrappers::EdgeWrapper.new graph, item
            wrapped
          else
            item
          end
        end
      end
    end

    class UnwrappingPipeFunction
      include com.tinkerpop.pipes.PipeFunction

      attr_reader :block

      def initialize(block)
        @block = block
      end

      def arity
        block.arity
      end

      def compute(element)
        e = block.call element
        if e.is_a? ElementWrapper
          e.element
        else
          e
        end
      end

      alias call compute

      def call_with_args(element, *args)
        e = block.call element, *args
        if e.is_a? ElementWrapper
          e.element
        else
          e
        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/wrapping_pipe_function.rb
pacer-2.0.22-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.20-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.19-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.18-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.17-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.16-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.15-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.14-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.13-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.12-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.10-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.10.pre-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.8-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.6-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.4.pre-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-2.0.0.pre-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.6.0-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.5.4-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.5.3-java lib/pacer/wrappers/wrapping_pipe_function.rb