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-1.5.2-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.5.1-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.4.2-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.4.1-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.4.0-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.3.5-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.3.4-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.3.3-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.3.2-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.3.1-java lib/pacer/wrappers/wrapping_pipe_function.rb
pacer-1.2.0-java lib/pacer/wrappers/wrapping_pipe_function.rb