Class: Neo4j::Server::CypherRelationship
Constant Summary
PropertyValidator::VALID_PROPERTY_VALUE_CLASSES
Instance Attribute Summary collapse
Attributes included from Resource
#resource_data, #resource_url
Instance Method Summary
collapse
#persisted?
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.
7
8
9
10
11
12
13
14
15
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 7
def initialize(session, value)
@session = session
@response_hash = value
@rel_type = @response_hash[:type]
@props = @response_hash[:data]
@start_node_neo_id = neo_id_integer(@response_hash[:start])
@end_node_neo_id = neo_id_integer(@response_hash[:end])
@id = @response_hash[:id]
end
|
Instance Attribute Details
#end_node_neo_id ⇒ Object
Returns the value of attribute end_node_neo_id.
40
41
42
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 40
def end_node_neo_id
@end_node_neo_id
end
|
#id ⇒ Object
Returns the value of attribute id.
22
23
24
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 22
def id
@id
end
|
#start_node_neo_id ⇒ Object
Returns the value of attribute start_node_neo_id.
38
39
40
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 38
def start_node_neo_id
@start_node_neo_id
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
17
18
19
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 17
def ==(other)
other.class == self.class && other.neo_id == neo_id
end
|
#_end_node ⇒ Object
54
55
56
57
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 54
def _end_node
load_resource
@_end_node ||= Neo4j::Node._load(end_node_neo_id)
end
|
#_end_node_id ⇒ Object
46
47
48
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 46
def _end_node_id
@end_node_neo_id ||= get_node_id(:end)
end
|
#_start_node ⇒ Object
50
51
52
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 50
def _start_node
@_start_node ||= Neo4j::Node._load(start_node_neo_id)
end
|
#_start_node_id ⇒ Object
42
43
44
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 42
def _start_node_id
@start_node_neo_id ||= get_node_id(:start)
end
|
#del ⇒ Object
Also known as:
delete, destroy
113
114
115
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 113
def del
@session._query("#{match_start} DELETE n", neo_id: neo_id)
end
|
#exist? ⇒ Boolean
119
120
121
122
123
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 119
def exist?
response = @session._query("#{match_start} RETURN n", neo_id: neo_id)
(response.data.nil? || response.data.empty?) ? false : true
end
|
#get_node_id(direction) ⇒ Object
59
60
61
62
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 59
def get_node_id(direction)
load_resource
resource_url_id(resource_url(direction))
end
|
#get_property(key) ⇒ Object
64
65
66
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 64
def get_property(key)
@session._query_or_fail("#{match_start} RETURN n.`#{key}`", true, neo_id: neo_id)
end
|
#inspect ⇒ Object
28
29
30
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 28
def inspect
"CypherRelationship #{neo_id}"
end
|
#load_resource ⇒ Object
32
33
34
35
36
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 32
def load_resource
return if resource_data_present?
@resource_data = @session._query_or_fail("#{match_start} RETURN n", true, neo_id: neo_id) end
|
#neo_id ⇒ Object
24
25
26
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 24
def neo_id
id
end
|
#props ⇒ Hash<Symbol,Object>
Returns all properties of the relationship.
77
78
79
80
81
82
83
84
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 77
def props
if @props
@props
else
hash = @session._query_entity_data("#{match_start} RETURN n", nil, neo_id: neo_id)
@props = Hash[hash[:data].map { |k, v| [k, v] }]
end
end
|
#props=(properties) ⇒ Object
replace all properties with new properties
87
88
89
90
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 87
def props=(properties)
@session._query_or_fail("#{match_start} SET n = { props }", false, props: properties, neo_id: neo_id)
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
72
73
74
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 72
def remove_property(key)
@session._query_or_fail("#{match_start} REMOVE n.`#{key}`", false, neo_id: neo_id)
end
|
#set_property(key, value) ⇒ Object
68
69
70
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 68
def set_property(key, value)
@session._query_or_fail("#{match_start} SET n.`#{key}` = {value}", false, value: value, neo_id: neo_id)
end
|
#update_props(properties) ⇒ Object
Updates the properties, keeps old properties
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 93
def update_props(properties)
return if properties.empty?
params = {}
q = "#{match_start} SET " + properties.keys.each_with_index.map do |k, _i|
param = k.to_s.tr_s('^a-zA-Z0-9', '_').gsub(/^_+|_+$/, '')
params[param] = properties[k]
"n.`#{k}`= {#{param}}"
end.join(',')
@session._query_or_fail(q, false, params.merge(neo_id: neo_id))
properties
end
|