Class: Neo4j::Server::CypherRelationship
Constant Summary
Core::CypherTranslator::SANITIZE_ESCAPED_REGEXP
PropertyValidator::VALID_PROPERTY_VALUE_CLASSES
Instance Attribute Summary collapse
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
#initialize(session, value, rel_type = nil) ⇒ CypherRelationship
Returns a new instance of CypherRelationship.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 10
def initialize(session, value, rel_type = nil)
@session = session
@id = if value.is_a?(Hash)
@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
@response_hash['id']
else
@rel_type = rel_type
value
end
end
|
Instance Attribute Details
#end_node_neo_id ⇒ Object
Returns the value of attribute end_node_neo_id.
8
9
10
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 8
def end_node_neo_id
@end_node_neo_id
end
|
#start_node_neo_id ⇒ Object
Returns the value of attribute start_node_neo_id.
8
9
10
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 8
def start_node_neo_id
@start_node_neo_id
end
|
Instance Method Details
#==(o) ⇒ Object
Also known as:
eql?
27
28
29
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 27
def ==(o)
o.class == self.class && o.neo_id == neo_id
end
|
#_end_node ⇒ Object
61
62
63
64
65
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 61
def _end_node
load_resource
id = resource_url_id(resource_url(:end))
Neo4j::Node._load(id)
end
|
#_end_node_id ⇒ Object
51
52
53
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 51
def _end_node_id
@end_node_neo_id ||= get_node_id(:end)
end
|
#_start_node ⇒ Object
55
56
57
58
59
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 55
def _start_node
load_resource
id = resource_url_id(resource_url(:start))
Neo4j::Node._load(id)
end
|
#_start_node_id ⇒ Object
47
48
49
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 47
def _start_node_id
@start_node_neo_id ||= get_node_id(:start)
end
|
#del ⇒ Object
117
118
119
120
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 117
def del
id = neo_id
@session._query("START n=relationship(#{id}) DELETE n").raise_unless_response_code(200)
end
|
#exist? ⇒ Boolean
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 122
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
67
68
69
70
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 67
def get_node_id(direction)
load_resource
resource_url_id(resource_url(direction))
end
|
#get_property(key) ⇒ Object
72
73
74
75
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 72
def get_property(key)
id = neo_id
@session._query_or_fail("START n=relationship(#{id}) RETURN n.`#{key}`", true)
end
|
#inspect ⇒ Object
36
37
38
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 36
def inspect
"CypherRelationship #{neo_id}"
end
|
#load_resource ⇒ Object
40
41
42
43
44
45
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 40
def load_resource
id = neo_id
unless @resource_data
@resource_data = @session._query_or_fail("START n=relationship(#{id}) RETURN n", true) end
end
|
#neo_id ⇒ Object
32
33
34
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 32
def neo_id
@id
end
|
#props ⇒ Hash<Symbol,Object>
Returns all properties of the relationship.
88
89
90
91
92
93
94
95
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 88
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
98
99
100
101
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 98
def props=(properties)
@session._query_or_fail("START n=relationship(#{neo_id}) SET n = { props }", false, {props: properties})
properties
end
|
#rel_type ⇒ Object
113
114
115
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 113
def rel_type
@rel_type.to_sym
end
|
#remove_property(key) ⇒ Object
82
83
84
85
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 82
def remove_property(key)
id = neo_id
@session._query_or_fail("START n=relationship(#{id}) REMOVE n.`#{key}`")
end
|
#set_property(key, value) ⇒ Object
77
78
79
80
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 77
def set_property(key,value)
id = neo_id
@session._query_or_fail("START n=relationship(#{id}) SET n.`#{key}` = {value}", false, {value: value})
end
|
#update_props(properties) ⇒ Object
Updates the properties, keeps old properties
104
105
106
107
108
109
110
111
|
# File 'lib/neo4j-server/cypher_relationship.rb', line 104
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
|