neo4apis 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/neo4apis/base.rb +35 -13
- data/neo4apis.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 959d680c2dde5dcfd1fd964faca6d3bebb41cc92
|
4
|
+
data.tar.gz: 5752b466c52b785c1e120df8eacd461288f355c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9170517c8f5d446bc0ba93b3069910501fdf5e41c9168affe9ec18b509b12c5482be8b11f1eb5440eaa3d101b14acdf0c9809cb00e384df60cd6e0a1cf6d8fda
|
7
|
+
data.tar.gz: fe9290e06c5bd77bae2c0f57e38d3993f3cca58015d641df6edb369232a2c30ee4e7359ef3f80c5e1467cbe975b1b5260c911f5e77378445a257f53a583415a3
|
data/README.md
CHANGED
@@ -72,3 +72,15 @@ end
|
|
72
72
|
|
73
73
|
```
|
74
74
|
|
75
|
+
## Options
|
76
|
+
|
77
|
+
Options can be used in the instantiation of the Neo4Apis client:
|
78
|
+
|
79
|
+
neo4apis_awesome = Neo4Apis::AwesomeSite.new(neo4j_session, {option: value})
|
80
|
+
|
81
|
+
|
82
|
+
`relationship_transform`
|
83
|
+
|
84
|
+
Allowed values `upcase`, `downcase`, and `none`. Default: `upcase`
|
85
|
+
|
86
|
+
How should relationship types be transformed when saving? Neo4j recommends upper case relationship types, so `upcase` is the default. `none` sends through relationship types as specified in the add_relationship method
|
data/lib/neo4apis/base.rb
CHANGED
@@ -24,7 +24,7 @@ module Neo4Apis
|
|
24
24
|
|
25
25
|
if object
|
26
26
|
columns.each do |column|
|
27
|
-
props
|
27
|
+
props[column] = object.send(column)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -118,23 +118,45 @@ module Neo4Apis
|
|
118
118
|
private
|
119
119
|
|
120
120
|
def create_node_query(node_proxy)
|
121
|
-
|
122
|
-
merge(node: {node_proxy.label => {node_proxy.uuid_field => node_proxy.uuid_value}}).
|
123
|
-
break.
|
124
|
-
set(node: node_proxy.props)
|
121
|
+
return if node_proxy.props.empty?
|
125
122
|
|
126
|
-
|
123
|
+
cypher = <<-QUERY
|
124
|
+
MERGE (node:`#{node_proxy.label}` {#{node_proxy.uuid_field}: {uuid_value}})
|
125
|
+
SET #{set_attributes(:node, node_proxy.props.keys)}
|
126
|
+
QUERY
|
127
127
|
|
128
|
-
|
128
|
+
cypher << " SET node:`#{self.class.common_label}`" if self.class.common_label
|
129
|
+
|
130
|
+
OpenStruct.new({to_cypher: cypher,
|
131
|
+
merge_params: {uuid_value: node_proxy.uuid_value, props: node_proxy.props}})
|
129
132
|
end
|
130
133
|
|
131
134
|
def create_relationship_query(type, source, target, props)
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
return if props.empty?
|
136
|
+
|
137
|
+
type = type.to_s.send(relationship_transform) if relationship_transform != :none
|
138
|
+
|
139
|
+
cypher = <<-QUERY
|
140
|
+
MATCH (source:`#{source.label}`), (target:`#{source.label}`)
|
141
|
+
WHERE source.#{source.uuid_field}={source_value} AND target.#{target.uuid_field}={target_value}
|
142
|
+
MERGE source-[rel:`#{type}`]->target
|
143
|
+
SET #{set_attributes(:rel, props.keys)}
|
144
|
+
QUERY
|
145
|
+
|
146
|
+
OpenStruct.new({to_cypher: cypher,
|
147
|
+
merge_params: {source_value: source.uuid_value, target_value: target.uuid_value, props: props}})
|
148
|
+
end
|
149
|
+
|
150
|
+
def relationship_transform
|
151
|
+
(@options[:relationship_transform] || :upcase).to_sym.tap do |transform|
|
152
|
+
fail "Invalid relationship_transform value: #{transform.inspect}" if not [:upcase, :downcase, :none].include?(transform)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def set_attributes(var, properties)
|
157
|
+
properties.map do |property|
|
158
|
+
"#{var}.#{property} = {props}.#{property}"
|
159
|
+
end.join(', ')
|
138
160
|
end
|
139
161
|
|
140
162
|
def create_constraint_query(label, uuid_field)
|
data/neo4apis.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4apis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|