Class: Cadet::RelationshipTraverser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cadet/relationship_traverser.rb

Instance Method Summary collapse

Constructor Details

#initialize(node, direction, type) ⇒ RelationshipTraverser

Returns a new instance of RelationshipTraverser.



6
7
8
9
10
11
12
# File 'lib/cadet/relationship_traverser.rb', line 6

def initialize(node, direction, type)
  @node = node
  @type = type
  @direction = direction

  @relationships = node.get_relationships(direction, DynamicRelationshipType.withName(type))
end

Instance Method Details

#<<(othernode) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/cadet/relationship_traverser.rb', line 20

def << (othernode)
  if @direction == Direction::OUTGOING
    @node.create_outgoing othernode, @type
  elsif @direction == Direction::INCOMING
    othernode.create_outgoing @node, @type
  end
end

#eachObject



14
15
16
17
18
# File 'lib/cadet/relationship_traverser.rb', line 14

def each
  @relationships.each do |rel|
    yield Node.new rel.getOtherNode(@node.node)
  end
end