module Neography::Rest::Nodes
Public Instance Methods
create_empty_node()
click to toggle source
# File lib/neography/rest/nodes.rb, line 39 def create_empty_node @connection.post("/node") end
create_node(*args)
click to toggle source
# File lib/neography/rest/nodes.rb, line 23 def create_node(*args) if args[0].respond_to?(:each_pair) && args[0] create_node_with_attributes(args[0]) else create_empty_node end end
create_node_with_attributes(attributes)
click to toggle source
# File lib/neography/rest/nodes.rb, line 31 def create_node_with_attributes(attributes) options = { :body => attributes.delete_if { |k, v| v.nil? }.to_json, :headers => json_content_type } @connection.post("/node", options) end
create_nodes(nodes)
click to toggle source
# File lib/neography/rest/nodes.rb, line 47 def create_nodes(nodes) nodes = Array.new(nodes) if nodes.kind_of? Fixnum created_nodes = [] nodes.each do |node| created_nodes << create_node(node) end created_nodes end
create_nodes_threaded(nodes)
click to toggle source
# File lib/neography/rest/nodes.rb, line 56 def create_nodes_threaded(nodes) nodes = Array.new(nodes) if nodes.kind_of? Fixnum node_queue = Queue.new thread_pool = [] responses = Queue.new nodes.each do |node| node_queue.push node end [nodes.size, @connection.max_threads].min.times do thread_pool << Thread.new do until node_queue.empty? do node = node_queue.pop if node.respond_to?(:each_pair) responses.push( @connection.post("/node", { :body => node.to_json, :headers => json_content_type } ) ) else responses.push( @connection.post("/node") ) end end self.join end end created_nodes = [] while created_nodes.size < nodes.size created_nodes << responses.pop end created_nodes end
delete_node(id)
click to toggle source
# File lib/neography/rest/nodes.rb, line 43 def delete_node(id) @connection.delete("/node/%{id}" % {:id => get_id(id)}) end
get_node(id)
click to toggle source
# File lib/neography/rest/nodes.rb, line 6 def get_node(id) @connection.get("/node/%{id}" % {:id => get_id(id)}) end
get_nodes(*nodes)
click to toggle source
# File lib/neography/rest/nodes.rb, line 10 def get_nodes(*nodes) gotten_nodes = [] Array(nodes).flatten.each do |node| gotten_nodes << get_node(node) end gotten_nodes end
get_root()
click to toggle source
# File lib/neography/rest/nodes.rb, line 18 def get_root root_node = @connection.get('/')["reference_node"] @connection.get("/node/%{id}" % {:id => get_id(root_node)}) end