Class: Pacer::Pipes::VertexQueryPipe

Inherits:
RubyPipe
  • Object
show all
Defined in:
lib/pacer-titan/vertex_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(labels, direction, element_type, block = nil, limit = nil, order_by = {}) ⇒ VertexQueryPipe

Returns a new instance of VertexQueryPipe.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pacer-titan/vertex_query.rb', line 19

def initialize(labels, direction, element_type, block=nil, limit=nil, order_by={})
  super()
  @labels = labels
  @block = block
  @limit = limit
  @current_iterator = nil
  @order_by = order_by.keys.first if order_by
  @order_direction = order_by.values.first if order_by
  @element_type = element_type
  
  case direction.to_sym
  when :out
    @direction = com.tinkerpop.blueprints.Direction::OUT
  when :in
    @direction = com.tinkerpop.blueprints.Direction::IN
  when :both
    @direction = com.tinkerpop.blueprints.Direction::BOTH
  else
    raise "Invalid direction to VertexQueryPipe (use :out, :in, or :both)"
  end
  
  case @order_direction.try(:to_sym)
  when :asc
    @order_direction = com.thinkaurelius.titan.core.Order::ASC
  when :desc
    @order_direction = com.thinkaurelius.titan.core.Order::DESC
  else
    @order_direction = nil
  end
end

Instance Method Details

#processNextStartObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pacer-titan/vertex_query.rb', line 50

def processNextStart
  while true
    if @current_iterator.try(:has_next)
      return @current_iterator.next
    else
      vertex = starts.next
      query = vertex.query.direction(@direction).labels(@labels)
      query = query.instance_exec(&@block) if @block
      query = query.order_by(@order_by.to_s, @order_direction) if @order_by && @order_direction
      query = query.limit(@limit) if @limit
      if @element_type == :vertex
        @current_iterator = query.vertices.iterator
      else
        @current_iterator = query.edges.iterator
      end
    end
  end
end