Skip to content

Commit

Permalink
Missed a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Darrick Wiebe committed Oct 24, 2012
1 parent ff802b1 commit 45419cf
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pacer/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module SideEffect end
require 'pacer/wrappers/index_wrapper'
require 'pacer/wrappers/wrapper_selector'
require 'pacer/wrappers/wrapping_pipe_function'
require 'pacer/wrappers/path_wrapping_pipe_function'

require 'pacer/route_builder'
require 'pacer/function_resolver'
Expand Down
85 changes: 85 additions & 0 deletions lib/pacer/wrappers/path_wrapping_pipe_function.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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
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

0 comments on commit 45419cf

Please sign in to comment.