Class: Neon::Node::Rest
- Inherits:
-
Object
- Object
- Neon::Node::Rest
- Includes:
- PropertyContainer::Rest
- Defined in:
- lib/neon/node/rest.rb
Constant Summary collapse
- QUERIES =
Move to a separate file
{ :[] => lambda do |node, *keys| query = "START n = node({id})\nWITH " query << keys.map { |key| "n.#{key.to_s.strip} as #{key.to_s.strip}" }.join(", ") query << "\nRETURN " query << keys.map { |key| key.to_s.strip }.join(", ") [query, {id: node.id}] end }
- RESULT_PARSER =
Move to a seprate file
{ :[] => lambda do |result, *keys| parsed_result = [] result = result.first columns = result["columns"] data = result["data"].first["row"].dup raise "Corrupted result" if columns.length != keys.length for i in 0...keys.length parsed_result << if keys[i] == columns[i] data.shift else nil end end if keys.length == 1 parsed_result.pop else parsed_result end end }
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The neo id of this node.
-
#node ⇒ Object
readonly
The neography hash containing information about the node.
-
#session ⇒ Object
readonly
The Rest session this node belongs to.
Instance Method Summary collapse
-
#create_rel_to(end_node, type, attributes = {}) ⇒ Relationship::Rest
Create a unidirectional relationship starting from this node to another node.
-
#initialize(node, session) ⇒ Node::Rest
constructor
Initialize the node with a neography node and a REST session.
- #parse_result(result, method, *args) ⇒ Object
- #query_for(method, *args) ⇒ Object
- #to_s ⇒ Object
Methods included from PropertyContainer::Rest
#==, #[], #[]=, #del, #destroy, #props, #props=
Methods included from TransactionHelpers::Rest
Constructor Details
#initialize(node, session) ⇒ Node::Rest
Initialize the node with a neography node and a REST session
17 18 19 20 21 |
# File 'lib/neon/node/rest.rb', line 17 def initialize(node, session) @session = session # Set the session @node = node # Set the node @id = node["self"].split('/').last.to_i # Set the id end |
Instance Attribute Details
#id ⇒ Object (readonly)
The neo id of this node.
8 9 10 |
# File 'lib/neon/node/rest.rb', line 8 def id @id end |
#node ⇒ Object (readonly)
The neography hash containing information about the node.
9 10 11 |
# File 'lib/neon/node/rest.rb', line 9 def node @node end |
#session ⇒ Object (readonly)
The Rest session this node belongs to.
7 8 9 |
# File 'lib/neon/node/rest.rb', line 7 def session @session end |
Instance Method Details
#create_rel_to(end_node, type, attributes = {}) ⇒ Relationship::Rest
Create a unidirectional relationship starting from this node to another node.
34 35 36 37 38 39 40 41 42 |
# File 'lib/neon/node/rest.rb', line 34 def create_rel_to(end_node, type, attributes = {}) return nil if @session.url != end_node.session.url attributes.delete_if { |key, value| value.nil? } neo_rel = @session.neo.create_relationship(type, @node, end_node.node, attributes) return nil if neo_rel.nil? rel = Relationship::Rest.new(neo_rel, @session) rescue NoMethodError => e _raise_doesnt_exist_anymore_error(e) end |
#parse_result(result, method, *args) ⇒ Object
83 84 85 |
# File 'lib/neon/node/rest.rb', line 83 def parse_result(result, method, *args) RESULT_PARSER[method].call(result, *args) end |
#query_for(method, *args) ⇒ Object
55 56 57 58 |
# File 'lib/neon/node/rest.rb', line 55 def query_for(method, *args) # Fetch appropriate query and covert the args to a hash corresponding the query parameters QUERIES[method].call(self, *args) end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/neon/node/rest.rb', line 23 def to_s "REST Node[#{@id}]" end |