Class: Neo4j::Server::CypherRelationship
Constant Summary
Core::CypherTranslator::SANITIZE_ESCAPED_REGEXP
PropertyValidator::VALID_PROPERTY_VALUE_CLASSES
Instance Attribute Summary
Attributes included from Resource
#resource_data, #resource_url
Instance Method Summary
collapse
#persisted?
#cypher_prop_list, #escape_quotes, #escape_value, #sanitize_escape_sequences, sanitized_column_names, translate_response
Methods included from Resource
#convert_from_json_value, #expect_response_code, #handle_response_error, #init_resource_data, #resource_headers, #resource_url_id, #response_exception, #wrap_resource
_load, #_other_node, create, #end_node, load, #other_node, #start_node
#neo4j_obj, #wrapper
#[], #[]=
#valid_property?, #validate_property
Constructor Details
Returns a new instance of CypherRelationship.
8
9
10
11
12
13
14
15
16
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 8
def initialize(session, value)
@session = session
@response_hash = value
@rel_type = @response_hash['type']
@props = @response_hash['data']
@start_node_neo_id = @response_hash['start'].match(/\d+$/)[0].to_i
@end_node_neo_id = @response_hash['end'].match(/\d+$/)[0].to_i
@id = @response_hash['id']
end
|
Instance Method Details
#==(o) ⇒ Object
Also known as:
eql?
18
19
20
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 18
def ==(o)
o.class == self.class && o.neo_id == neo_id
end
|
#_end_node ⇒ Object
61
62
63
64
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 61
def _end_node
load_resource
@_end_node ||= Neo4j::Node._load(end_node_neo_id)
end
|
#_end_node_id ⇒ Object
53
54
55
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 53
def _end_node_id
@end_node_neo_id ||= get_node_id(:end)
end
|
#_start_node ⇒ Object
57
58
59
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 57
def _start_node
@_start_node ||= Neo4j::Node._load(start_node_neo_id)
end
|
#_start_node_id ⇒ Object
49
50
51
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 49
def _start_node_id
@start_node_neo_id ||= get_node_id(:start)
end
|
#del ⇒ Object
Also known as:
delete, destroy
113
114
115
116
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 113
def del
id = neo_id
@session._query("START n=relationship(#{id}) DELETE n").raise_unless_response_code(200)
end
|
#end_node_neo_id ⇒ Object
45
46
47
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 45
def end_node_neo_id
@end_node_neo_id
end
|
#exist? ⇒ Boolean
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 120
def exist?
id = neo_id
response = @session._query("START n=relationship(#{id}) RETURN n")
if (!response.error?)
return true
elsif (response.error_status == 'BadInputException') return false
else
response.raise_error
end
end
|
#get_node_id(direction) ⇒ Object
66
67
68
69
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 66
def get_node_id(direction)
load_resource
resource_url_id(resource_url(direction))
end
|
#get_property(key) ⇒ Object
71
72
73
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 71
def get_property(key)
@session._query_or_fail("START n=relationship(#{id}) RETURN n.`#{key}`", true)
end
|
#id ⇒ Object
23
24
25
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 23
def id
@id
end
|
#inspect ⇒ Object
31
32
33
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 31
def inspect
"CypherRelationship #{neo_id}"
end
|
#load_resource ⇒ Object
35
36
37
38
39
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 35
def load_resource
if resource_data.nil? || resource_data.empty?
@resource_data = @session._query_or_fail("START n=relationship(#{id}) RETURN n", true) end
end
|
#neo_id ⇒ Object
27
28
29
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 27
def neo_id
id
end
|
#props ⇒ Hash<Symbol,Object>
Returns all properties of the relationship.
84
85
86
87
88
89
90
91
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 84
def props
if @props
@props
else
hash = @session._query_entity_data("START n=relationship(#{neo_id}) RETURN n")
@props = Hash[hash['data'].map{ |k, v| [k.to_sym, v] }]
end
end
|
#props=(properties) ⇒ Object
replace all properties with new properties
94
95
96
97
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 94
def props=(properties)
@session._query_or_fail("START n=relationship(#{neo_id}) SET n = { props }", false, {props: properties})
properties
end
|
#rel_type ⇒ Object
109
110
111
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 109
def rel_type
@rel_type.to_sym
end
|
#remove_property(key) ⇒ Object
79
80
81
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 79
def remove_property(key)
@session._query_or_fail("START n=relationship(#{id}) REMOVE n.`#{key}`")
end
|
#set_property(key, value) ⇒ Object
75
76
77
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 75
def set_property(key,value)
@session._query_or_fail("START n=relationship(#{id}) SET n.`#{key}` = {value}", false, {value: value})
end
|
#start_node_neo_id ⇒ Object
41
42
43
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 41
def start_node_neo_id
@start_node_neo_id
end
|
#update_props(properties) ⇒ Object
Updates the properties, keeps old properties
100
101
102
103
104
105
106
107
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 100
def update_props(properties)
return if properties.empty?
q = "START n=relationship(#{neo_id}) SET " + properties.keys.map do |k|
"n.`#{k}`= #{escape_value(properties[k])}"
end.join(',')
@session._query_or_fail(q)
properties
end
|