neo4j-core 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d3cbf5325e61b512d3ee45eb02a58125794fc80
4
- data.tar.gz: db9a665ef9d8a6dade91ad8f715969737d21390a
3
+ metadata.gz: 413db701027dd75c0757902fba22db6a5b289781
4
+ data.tar.gz: 59d07ba453f252c053fbd6b353b3604415cd3a0f
5
5
  SHA512:
6
- metadata.gz: 17b7d282f266d5167f92eeec3c06daf0d5321eed771d895544dadcb0f2dc8346f97e612d67156a43d033093caa805f1b18c03f010c65775966068c8768f30145
7
- data.tar.gz: 7d3023581c880837bfc13d714b873303012d01cd3fcd6ae3409e419220e488a960c3517ad590c48e14bcdb5a49f8360c991dd6fa39da19537444174c9ec8b850
6
+ metadata.gz: cf46b06d8cf1c4b4152fe7ce4f870ca019cdb475d06a2e2d902db223c7d6d2c8abf20b44cba5a352e3e3b4122d4e79e698bdc105a169e41fdc51bca506958474
7
+ data.tar.gz: 9dcdf5e2fdb993c3de4203a0e21029bc497fd6562096bdd6b76b761565c0e56206f16cccd2bc449d5625c8235931f4312810697ed2b547a41d3fb42286d98bb1
data/Gemfile CHANGED
@@ -2,8 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'zip'
6
-
7
5
  # gem 'neo4j-advanced', '>= 1.8.1', '< 2.0', :require => false
8
6
  # gem 'neo4j-enterprise', '>= 1.8.1', '< 2.0', :require => false
9
7
 
@@ -14,7 +12,6 @@ end
14
12
  group 'test' do
15
13
  gem 'coveralls', require: false
16
14
  gem 'simplecov-html', require: false
17
- gem 'rake', '>= 0.8.7'
18
15
  gem 'rspec', '~> 3.0'
19
16
  gem 'rspec-its'
20
17
  end
data/README.md CHANGED
@@ -1,25 +1,51 @@
1
- # Neo4j-core v3.0 [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j-core.png)](https://codeclimate.com/github/neo4jrb/neo4j-core) [![Build Status](https://travis-ci.org/neo4jrb/neo4j-core.png)](https://travis-ci.org/neo4jrb/neo4j-core) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j-core/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j-core?branch=master) [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j-core/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j-core/reviews/master)
1
+ # Neo4j-core [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j-core.png)](https://codeclimate.com/github/neo4jrb/neo4j-core) [![Build Status](https://travis-ci.org/neo4jrb/neo4j-core.png)](https://travis-ci.org/neo4jrb/neo4j-core) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j-core/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j-core?branch=master) [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j-core/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j-core/reviews/master)
2
2
 
3
3
  A simple Ruby wrapper around the Neo4j graph database that works with the server and embedded Neo4j API. This gem can be used both from JRuby and normal MRI.
4
4
  It can be used standalone without the neo4j gem.
5
5
 
6
6
  ## Documentation
7
7
 
8
- * [3.0 Documentation](https://github.com/neo4jrb/neo4j-core/wiki)
9
- * [2.x Documentation](https://github.com/neo4jrb/neo4j-core/tree/v2.x)
8
+ ### 3.0+ Documentation:
10
9
 
10
+ * http://neo4jrb.readthedocs.org/en/stable/
11
+ * https://github.com/neo4jrb/neo4j-core/wiki
12
+
13
+ ### 2.x Documentation
14
+
15
+ https://github.com/neo4jrb/neo4j-core/tree/v2.x
11
16
 
12
17
  ## Support
13
18
 
14
- * [Neo4j.rb mailing list](https://groups.google.com/forum/#!forum/neo4jrb)
15
- * Consulting support ? ask any of the developers
19
+ ### Issues
20
+
21
+ [![Next Release](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=Next%20Release&title=Next%20Release) ![In Progress](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=In%20Progress&title=In%20Progress) ![In Master](https://badge.waffle.io/neo4jrb/neo4j-core.png?label=In%20Master&title=In%20Master)](https://waffle.io/neo4jrb/neo4j-core)
22
+
23
+ [![Post an issue](https://img.shields.io/badge/Bug%3F-Post%20an%20issue!-blue.svg)](https://waffle.io/neo4jrb/neo4j-core)
24
+
25
+
26
+ ### Get Support
27
+
28
+ #### Documentation
29
+
30
+ All new documentation will be done via our [readthedocs](http://neo4jrb.readthedocs.org) site, though some old documentation has yet to be moved from our [wiki](https://github.com/neo4jrb/neo4j/wiki) (also there is the [neo4j-core wiki](https://github.com/neo4jrb/neo4j-core/wiki))
31
+
32
+ #### Contact Us
33
+
34
+ [![StackOverflow](https://img.shields.io/badge/StackOverflow-Ask%20a%20question!-blue.svg)](http://stackoverflow.com/questions/ask?tags=neo4j.rb+neo4j+ruby) [![Gitter](https://img.shields.io/badge/Gitter-Join%20our%20chat!-blue.svg)](https://gitter.im/neo4jrb/neo4j?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Twitter](https://img.shields.io/badge/Twitter-Tweet%20with%20us!-blue.svg)](https://twitter.com/neo4jrb) [![Mailing list](https://img.shields.io/badge/Mailing%20list-Mail%20us!-blue.svg)](https://groups.google.com/forum/#!forum/neo4jrb)
35
+
16
36
 
17
37
  ## Developers
18
38
 
19
- * [Andreas Ronge](https://github.com/neo4jrb)
39
+ ### Original Author
40
+
41
+ * [Andreas Ronge](https://github.com/andreasronge)
42
+
43
+ ### Current Maintainers
44
+
20
45
  * [Brian Underwood](https://github.com/cheerfulstoic)
21
46
  * [Chris Grigg](https://github.com/subvertallchris)
22
47
 
48
+ Consulting support? Contact [Chris](http://subvertallmedia.com/) and/or [Brian](http://www.brian-underwood.codes/)
23
49
 
24
50
  ## Contributing
25
51
 
data/lib/neo4j/ansi.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Neo4j
2
+ module ANSI
3
+ CLEAR = "\e[0m"
4
+ BOLD = "\e[1m"
5
+
6
+ RED = "\e[31m"
7
+ GREEN = "\e[32m"
8
+ YELLOW = "\e[33m"
9
+ BLUE = "\e[34m"
10
+ MAGENTA = "\e[35m"
11
+ CYAN = "\e[36m"
12
+ WHITE = "\e[37m"
13
+ end
14
+ end
data/lib/neo4j/label.rb CHANGED
@@ -60,7 +60,6 @@ module Neo4j
60
60
  end
61
61
 
62
62
  class << self
63
- include Neo4j::Core::CypherTranslator
64
63
  INDEX_PATH = '/db/data/schema/index/'
65
64
  CONSTRAINT_PATH = '/db/data/schema/constraint/'
66
65
 
data/lib/neo4j/node.rb CHANGED
@@ -168,7 +168,12 @@ module Neo4j
168
168
  class << self
169
169
  # Creates a node
170
170
  def create(props = nil, *labels_or_db)
171
- session = Neo4j::Core::ArgumentHelper.session(labels_or_db)
171
+ session = if labels_or_db.last.is_a?(Neo4j::Session)
172
+ labels_or_db.pop
173
+ else
174
+ Neo4j::Session.current!
175
+ end
176
+
172
177
  session.create_node(props, labels_or_db)
173
178
  end
174
179
 
@@ -1,18 +1,13 @@
1
1
  module Neo4j
2
2
  module Core
3
- module ArgumentHelper
4
- def self.session(args)
5
- args.last.is_a?(Neo4j::Session) ? args.pop : Neo4j::Session.current!
6
- end
7
- end
8
-
9
3
  module TxMethods
10
4
  def tx_methods(*methods)
11
5
  methods.each do |method|
12
6
  tx_method = "#{method}_in_tx"
13
7
  send(:alias_method, tx_method, method)
14
8
  send(:define_method, method) do |*args, &block|
15
- session = ArgumentHelper.session(args)
9
+ session = args.last.is_a?(Neo4j::Session) ? args.pop : Neo4j::Session.current!
10
+
16
11
  Neo4j::Transaction.run(session.auto_commit?) { send(tx_method, *args, &block) }
17
12
  end
18
13
  end
@@ -18,6 +18,10 @@ module Neo4j
18
18
 
19
19
  attr_accessor :clauses
20
20
 
21
+ class << self
22
+ attr_accessor :pretty_cypher
23
+ end
24
+
21
25
  def initialize(options = {})
22
26
  @session = options[:session] || Neo4j::Session.current
23
27
 
@@ -26,6 +30,10 @@ module Neo4j
26
30
  @_params = {}
27
31
  end
28
32
 
33
+ def inspect
34
+ "#<Query CYPHER: #{ANSI::YELLOW}#{to_cypher.inspect}#{ANSI::CLEAR}>"
35
+ end
36
+
29
37
  # @method start *args
30
38
  # START clause
31
39
  # @return [Query]
@@ -133,6 +141,12 @@ module Neo4j
133
141
  query.order(*args)
134
142
  end
135
143
 
144
+ # Works the same as the #where method, but the clause is surrounded by a
145
+ # Cypher NOT() function
146
+ def where_not(*args)
147
+ build_deeper_query(WhereClause, args, not: true)
148
+ end
149
+
136
150
  # Works the same as the #set method, but when given a nested array it will set properties rather than setting entire objects
137
151
  # @example
138
152
  # # Creates a query representing the cypher: MATCH (n:Person) SET n.age = 19
@@ -174,9 +188,10 @@ module Neo4j
174
188
  def response
175
189
  return @response if @response
176
190
  cypher = to_cypher
177
- @response = ActiveSupport::Notifications.instrument('neo4j.cypher_query', context: @options[:context] || 'CYPHER', cypher: cypher, params: merge_params) do
178
- @session._query(cypher, merge_params)
179
- end
191
+ pretty_cypher = to_cypher(pretty: true) if self.class.pretty_cypher
192
+
193
+ @response = @session._query(cypher, merge_params, context: @options[:context], pretty_cypher: pretty_cypher)
194
+
180
195
  if !response.respond_to?(:error?) || !response.error?
181
196
  response
182
197
  else
@@ -184,6 +199,17 @@ module Neo4j
184
199
  end
185
200
  end
186
201
 
202
+ def match_nodes(hash)
203
+ hash.inject(self) do |query, (variable, node_object)|
204
+ neo_id = if node_object.respond_to?(:neo_id)
205
+ node_object.neo_id
206
+ else
207
+ node_object
208
+ end
209
+ query.match(variable).where(variable => {neo_id: neo_id})
210
+ end
211
+ end
212
+
187
213
  include Enumerable
188
214
 
189
215
  def count(var = nil)
@@ -257,22 +283,27 @@ module Neo4j
257
283
  #
258
284
  # @return [String] Resulting cypher query string
259
285
  EMPTY = ' '
260
- def to_cypher
286
+ NEWLINE = "\n"
287
+ def to_cypher(options = {})
261
288
  cypher_string = PartitionedClauses.new(@clauses).map do |clauses|
262
289
  clauses_by_class = clauses.group_by(&:class)
263
290
 
264
291
  cypher_parts = CLAUSES.map do |clause_class|
265
- clause_class.to_cypher(clauses) if clauses = clauses_by_class[clause_class]
292
+ clause_class.to_cypher(clauses, options) if clauses = clauses_by_class[clause_class]
266
293
  end
267
294
 
268
295
  cypher_parts.compact!
269
- cypher_parts.join(EMPTY).tap(&:strip!)
270
- end.join EMPTY
296
+ cypher_parts.join(options[:pretty] ? NEWLINE : EMPTY).tap(&:strip!)
297
+ end.join(options[:pretty] ? NEWLINE : EMPTY)
271
298
 
272
299
  cypher_string = "CYPHER #{@options[:parser]} #{cypher_string}" if @options[:parser]
273
300
  cypher_string.tap(&:strip!)
274
301
  end
275
302
 
303
+ def print_cypher
304
+ puts to_cypher(pretty: true).gsub(/\e[^m]+m/, '')
305
+ end
306
+
276
307
  # Returns a CYPHER query specifying the union of the callee object's query and the argument's query
277
308
  #
278
309
  # @example