-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Darrick Wiebe
committed
Oct 24, 2012
1 parent
ff802b1
commit 45419cf
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |