Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add payloads to elements.

  • Loading branch information...
commit d8c4ee6f6ce46dab0e682e2583e67249ff472898 1 parent 49112be
@pangloss pangloss authored
View
44 lib/pacer/blueprints/payload_elements.rb
@@ -0,0 +1,44 @@
+module Pacer
+ module Payload
+ class Element
+ include com.tinkerpop.blueprints.Element
+ extend Forwardable
+
+ def initialize(element, payload = nil)
+ @element = element
+ self.payload = payload
+ end
+
+ def inspect
+ "#<Payload #{ element.inspect } -- #{ payload.inspect }>"
+ end
+
+ attr_reader :element
+ attr_accessor :payload
+ end
+
+ class Edge < Element
+ include com.tinkerpop.blueprints.Edge
+
+ def_delegators :@element,
+ # Object
+ :equals, :toString, :hashCode,
+ # Element
+ :getId, :getPropertyKeys, :getProperty, :setProperty, :removeProperty, :getRawElement,
+ # Edge
+ :getLabel, :getVertex, :getRawEdge
+ end
+
+ class Vertex < Element
+ include com.tinkerpop.blueprints.Vertex
+
+ def_delegators :@element,
+ # Object
+ :equals, :toString, :hashCode,
+ # Element
+ :getId, :getPropertyKeys, :getProperty, :setProperty, :removeProperty, :getRawElement,
+ # Vertex
+ :getEdges, :getVertices, :query, :getRawVertex
+ end
+ end
+end
View
12 lib/pacer/core/graph/path_route.rb
@@ -29,6 +29,18 @@ def subgraph(target_graph = nil, opts = {})
target_graph
end
+ def payloads
+ map do |path|
+ path.map do |e|
+ if e.is_a? Pacer::Payload::Element
+ e.payload
+ elsif e.is_a? Pacer::Wrappers::ElementWrapper
+ e.element_payload
+ end
+ end
+ end
+ end
+
protected
def configure_iterator(iter)
View
3  lib/pacer/loader.rb
@@ -48,6 +48,8 @@ module SideEffect end
require 'pacer/blueprints/ruby_graph'
require 'pacer/blueprints/multi_graph'
+require 'pacer/blueprints/payload_elements'
+
require 'pacer/support/array_list'
require 'pacer/support/enumerable'
require 'pacer/support/proc'
@@ -86,6 +88,7 @@ module SideEffect end
require 'pacer/transform/scatter'
require 'pacer/transform/has_count_cap'
require 'pacer/transform/sort_section'
+require 'pacer/transform/payload'
require 'pacer/side_effect/aggregate'
require 'pacer/side_effect/as'
View
50 lib/pacer/transform/payload.rb
@@ -0,0 +1,50 @@
+module Pacer::Core::Graph::ElementRoute
+ def payload(&block)
+ chain_route transform: :payload, block: block
+ end
+end
+
+module Pacer::Transform
+ module Payload
+ attr_accessor :block
+
+ protected
+
+ def attach_pipe(end_pipe)
+ pipe = PayloadPipe.new(self, block)
+ pipe.setStarts end_pipe if end_pipe
+ pipe
+ end
+
+ class PayloadPipe < Pacer::Pipes::RubyPipe
+ field_reader :currentEnd
+
+ attr_reader :block, :wrapper
+
+ def initialize(route, block)
+ super()
+ if route.element_type == :edge
+ @wrapper = Pacer::Payload::Edge
+ elsif route.element_type == :vertex
+ @wrapper = Pacer::Payload::Vertex
+ else
+ fail Pacer::ClientError, 'Can not use PayloadPipe on non-element data'
+ end
+ block ||= proc { |el| nil }
+ @block = Pacer::Wrappers::WrappingPipeFunction.new route, block
+ end
+
+ def processNextStart
+ el = starts.next
+ @wrapper.new el, block.call(el)
+ end
+
+ def getPathToHere
+ path = super
+ path.remove path.size - 1
+ path.add currentEnd
+ path
+ end
+ end
+ end
+end
View
9 lib/pacer/wrappers/edge_wrapper.rb
@@ -4,9 +4,12 @@ class EdgeWrapper < ElementWrapper
include Pacer::Core::Graph::EdgesRoute
def_delegators :@element,
- :getId, :getLabel, :getPropertyKeys, :getProperty, :setProperty, :removeProperty,
- :getVertex,
- :getRawEdge
+ # Object
+ :equals, :toString, :hashCode,
+ # Element
+ :getId, :getPropertyKeys, :getProperty, :setProperty, :removeProperty, :getRawElement,
+ # Edge
+ :getLabel, :getVertex, :getRawEdge
class << self
def wrappers
View
4 lib/pacer/wrappers/element_wrapper.rb
@@ -160,6 +160,10 @@ def <=>(other)
display_name.to_s <=> other.display_name.to_s
end
+ def element_payload
+ element.payload if element.is_a? Pacer::Payload::Element
+ end
+
protected
def after_initialize
View
9 lib/pacer/wrappers/vertex_wrapper.rb
@@ -4,9 +4,12 @@ class VertexWrapper < ElementWrapper
include Pacer::Core::Graph::VerticesRoute
def_delegators :@element,
- :getId, :getPropertyKeys, :getProperty, :setProperty, :removeProperty,
- :getEdges,
- :getRawVertex
+ # Object
+ :equals, :toString, :hashCode,
+ # Element
+ :getId, :getPropertyKeys, :getProperty, :setProperty, :removeProperty, :getRawElement,
+ # Vertex
+ :getEdges, :getVertices, :query, :getRawVertex
class << self
def wrappers
Please sign in to comment.
Something went wrong with that request. Please try again.