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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9dc39e5d15243ff0fd5af9801cbee5effc409a7d
4
- data.tar.gz: cc39d6d2a1975b0b77a5a7582ec0da1351e13dc3
3
+ metadata.gz: 959d680c2dde5dcfd1fd964faca6d3bebb41cc92
4
+ data.tar.gz: 5752b466c52b785c1e120df8eacd461288f355c0
5
5
  SHA512:
6
- metadata.gz: ab9c88c313865a7d42d04f0ffa1ab12d0ed52e3ad016cbf982d54af3258dbdc0b824facb430c2c2c965f6bcde5d813cc9ce674769e45a203df11de62ec7957f9
7
- data.tar.gz: fbd2705473967bc5e41e3adb9ef80e8ee9eef09b8685bf4f64202387f155d6cad00be40e0c7d502e0545883eeb3e1f5ecb3f3f712b6907e529a43e8dd27dc66c
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
@@ -24,7 +24,7 @@ module Neo4Apis
24
24
 
25
25
  if object
26
26
  columns.each do |column|
27
- props.send("#{column}=", object.send(column))
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
- query = Neo4j::Core::Query.new.
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
- query = query.set("node:#{self.class.common_label}") if self.class.common_label
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
- query
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
- Neo4j::Core::Query.new.
133
- match(source: {source.label => {source.uuid_field => source.uuid_value}}).
134
- match(target: {target.label => {target.uuid_field => target.uuid_value}}).
135
- merge("source-[rel:#{type}]->target").
136
- break.
137
- set(rel: props)
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)
@@ -3,7 +3,7 @@ $:.unshift lib unless $:.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "neo4apis"
6
- s.version = '0.6.0'
6
+ s.version = '0.7.0'
7
7
  s.required_ruby_version = ">= 1.9.1"
8
8
 
9
9
  s.authors = "Brian Underwood"
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.6.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-16 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday