Sha256: 60d834e9fcf3736a3feea971635ab5ecda1c0131c1abd2df046bc115e00dd87b

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Neo4j

  class RelationshipTraverser
    include Enumerable
    include ToJava

    def initialize(node, types, dir)
      @node = node
      if types.size > 1
        @types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
      elsif types.size == 1
        @type = type_to_java(types[0])
      end

      @dir = dir_to_java(dir)
    end

    def each
      iterator.each {|i| yield i.wrapper}
    end

    def iterator
      if @types
        @node.get_relationships(@types).iterator
      elsif @type
        @node.get_relationships(@type, @dir).iterator
      else
        @node.get_relationships(@dir).iterator
      end
    end

    def size
      [*self].size
    end

    def both
      @dir = dir_to_java(:both)
      self
    end

    def incoming
      raise "Not allowed calling incoming when finding several relationships types" if @types
      @dir = dir_to_java(:incoming)
      self
    end

    def outgoing
      raise "Not allowed calling outgoing when finding several relationships types" if @types
      @dir = dir_to_java(:outgoing)
      self
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4j-1.0.0.beta.13 lib/neo4j/relationship_traverser.rb
neo4j-1.0.0.beta.12 lib/neo4j/relationship_traverser.rb