Enables creating and traversal of nodes in a list.
It uses the TimeLine api.neo4j.org/current/org/neo4j/index/timeline/Timeline.html,
Includes the Enumerable Mixin. The Neo4j::Mapping::ClassMethods::List#has_list methods returns an object of this type.
class Person include Neo4j::NodeMixin has_list :feeds end person = Person.new person.feeds << Neo4j::Node:new << Neo4j::Node.new
class Person include Neo4j::NodeMixin has_list :feeds end person = Person.new person.feeds[42] = (a = Neo4j::Node:new) person.feeds[1251] = Neo4j::Node.new person.feeds[42] # => a
# File lib/neo4j/has_list/mapping.rb, line 40 def initialize(indexer_for, node, name) @index = Neo4j.started_db.lucene.for_nodes("#{indexer_for.to_s.gsub('::', '_')}_#{name}-timeline", Neo4j::Config[:lucene][:exact]) @time_line = org.neo4j.index.lucene.LuceneTimeline.new(Neo4j.started_db.graph, @index) @node = node @name = name self.size = 0 unless size end
# File lib/neo4j/has_list/mapping.rb, line 138 def <<(other) @time_line.add(other._java_node, size) self.size = self.size + 1 self end
returns the first node with index n
# File lib/neo4j/has_list/mapping.rb, line 60 def [](n) @time_line.getBetween(n, n).first end
adds a node to the list with the given index n
# File lib/neo4j/has_list/mapping.rb, line 80 def []=(n, other_node) @time_line.add(other_node, n) self.size = self.size + 1 end
returns all nodes with the given index n
# File lib/neo4j/has_list/mapping.rb, line 65 def all(n) @time_line.getBetween(n, n) end
returns all the nodes between the given Range
# File lib/neo4j/has_list/mapping.rb, line 86 def between(range) @time_line.getBetween(range.first, range.end) end
Required by the Enumerable mixin so that we can
class Person include Neo4j::NodeMixin has_list :feeds end person.feeds.each {|node| node}
# File lib/neo4j/has_list/mapping.rb, line 107 def each @time_line.getBetween(java.lang.Long::MIN_VALUE,java.lang.Long::MAX_VALUE).iterator.each do |node| if @raw then yield node else yield node.wrapper end end end
same as #size == 0
# File lib/neo4j/has_list/mapping.rb, line 55 def empty? size == 0 end
returns the first node in the list or nil
# File lib/neo4j/has_list/mapping.rb, line 70 def first @time_line.getFirst() end
returns the last node in the list or nil
# File lib/neo4j/has_list/mapping.rb, line 75 def last @time_line.getLast end
If called then it will only return the raw java nodes and not the Ruby wrappers using the Neo4j::NodeMixin
# File lib/neo4j/has_list/mapping.rb, line 134 def raw @raw = true end
removes one node from the list and decrases the size of the list,
# File lib/neo4j/has_list/mapping.rb, line 91 def remove(node) @index.remove(node, "timestamp") self.size = self.size - 1 end
returns the size of this list notice in order to get correct result you must call the #remove method when an item is removed from the list
# File lib/neo4j/has_list/mapping.rb, line 50 def size @node["_list_size_#{@name}"] end