neo4j-core 8.1.4 → 9.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +71 -8
  3. data/lib/neo4j-core.rb +3 -49
  4. data/lib/neo4j/core.rb +4 -0
  5. data/lib/neo4j/core/config.rb +13 -0
  6. data/lib/neo4j/core/cypher_session/adaptors.rb +15 -15
  7. data/lib/neo4j/core/cypher_session/adaptors/bolt.rb +39 -48
  8. data/lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb +0 -4
  9. data/lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb +7 -3
  10. data/lib/neo4j/core/cypher_session/adaptors/embedded.rb +1 -2
  11. data/lib/neo4j/core/cypher_session/adaptors/has_uri.rb +4 -0
  12. data/lib/neo4j/core/cypher_session/adaptors/http.rb +1 -3
  13. data/lib/neo4j/core/cypher_session/responses.rb +1 -1
  14. data/lib/neo4j/core/cypher_session/responses/bolt.rb +0 -17
  15. data/lib/neo4j/core/cypher_session/responses/embedded.rb +9 -7
  16. data/lib/neo4j/core/cypher_session/responses/http.rb +3 -4
  17. data/lib/neo4j/core/cypher_session/transactions.rb +2 -0
  18. data/lib/{neo4j-core → neo4j/core}/helpers.rb +1 -14
  19. data/lib/neo4j/core/logging.rb +44 -0
  20. data/lib/{neo4j-core → neo4j/core}/query.rb +7 -6
  21. data/lib/{neo4j-core → neo4j/core}/query_clauses.rb +9 -16
  22. data/lib/{neo4j-core → neo4j/core}/query_find_in_batches.rb +3 -5
  23. data/lib/{neo4j-core → neo4j/core}/version.rb +1 -1
  24. data/lib/neo4j/transaction.rb +6 -8
  25. data/neo4j-core.gemspec +13 -11
  26. metadata +46 -50
  27. data/lib/ext/kernel.rb +0 -9
  28. data/lib/neo4j-core/active_entity.rb +0 -11
  29. data/lib/neo4j-core/label.rb +0 -9
  30. data/lib/neo4j-embedded.rb +0 -16
  31. data/lib/neo4j-embedded/cypher_response.rb +0 -71
  32. data/lib/neo4j-embedded/embedded_database.rb +0 -26
  33. data/lib/neo4j-embedded/embedded_ha_session.rb +0 -30
  34. data/lib/neo4j-embedded/embedded_impermanent_session.rb +0 -17
  35. data/lib/neo4j-embedded/embedded_label.rb +0 -88
  36. data/lib/neo4j-embedded/embedded_node.rb +0 -206
  37. data/lib/neo4j-embedded/embedded_relationship.rb +0 -77
  38. data/lib/neo4j-embedded/embedded_session.rb +0 -203
  39. data/lib/neo4j-embedded/embedded_transaction.rb +0 -30
  40. data/lib/neo4j-embedded/label.rb +0 -66
  41. data/lib/neo4j-embedded/property.rb +0 -106
  42. data/lib/neo4j-embedded/to_java.rb +0 -44
  43. data/lib/neo4j-server.rb +0 -12
  44. data/lib/neo4j-server/cypher_label.rb +0 -35
  45. data/lib/neo4j-server/cypher_node.rb +0 -221
  46. data/lib/neo4j-server/cypher_relationship.rb +0 -142
  47. data/lib/neo4j-server/cypher_response.rb +0 -248
  48. data/lib/neo4j-server/cypher_session.rb +0 -263
  49. data/lib/neo4j-server/cypher_transaction.rb +0 -100
  50. data/lib/neo4j-server/label.rb +0 -40
  51. data/lib/neo4j-server/resource.rb +0 -57
  52. data/lib/neo4j/entity_equality.rb +0 -8
  53. data/lib/neo4j/entity_marshal.rb +0 -20
  54. data/lib/neo4j/label.rb +0 -90
  55. data/lib/neo4j/node.rb +0 -216
  56. data/lib/neo4j/property_container.rb +0 -17
  57. data/lib/neo4j/property_validator.rb +0 -22
  58. data/lib/neo4j/relationship.rb +0 -161
  59. data/lib/neo4j/session.rb +0 -222
@@ -13,7 +13,6 @@ class ChunkWriterIO < StringIO
13
13
 
14
14
  # Write some bytes, splitting into chunks if necessary.
15
15
  def write_with_chunking(string)
16
- # Kernel.puts "Write!"
17
16
  until string.empty?
18
17
  future_size = @output_size + string.size
19
18
  if future_size >= MAX_CHUNK_SIZE
@@ -56,15 +55,12 @@ class ChunkWriterIO < StringIO
56
55
  def buffer_result(zero_chunk = false)
57
56
  result = ''
58
57
 
59
- # Kernel.puts 'result1', result.inspect
60
58
  if !@output_buffer.empty?
61
59
  result << [@output_size].pack('s>*')
62
60
  result.concat(@output_buffer.join)
63
61
  end
64
62
 
65
- # Kernel.puts 'result2', result.inspect
66
63
  result << "\x00\x00" if zero_chunk
67
- # Kernel.puts 'result3', result.inspect
68
64
 
69
65
  result
70
66
  end
@@ -31,8 +31,10 @@ module Neo4j
31
31
  DE: [:struct, 32]
32
32
  }
33
33
  # For efficiency. Translates directly from bytes to types
34
+ # Disabling because this needs to be able to change the hash inside the blocks
35
+ # There's probably a better way
34
36
  MARKER_TYPES.keys.each do |key|
35
- ord = eval("0x#{key}") # rubocop:disable Security/Eval
37
+ ord = key.to_s.to_i(16)
36
38
  MARKER_TYPES[ord] = MARKER_TYPES.delete(key)
37
39
  end
38
40
 
@@ -42,6 +44,7 @@ module Neo4j
42
44
  MARKER_BYTES.delete(key) if key.is_a?(Array)
43
45
  end
44
46
 
47
+
45
48
  MARKER_HEADERS = MARKER_TYPES.each_with_object({}) do |(byte, (type, size)), headers|
46
49
  headers[type] ||= {}
47
50
  headers[type][size] = [byte].pack('C')
@@ -64,7 +67,7 @@ module Neo4j
64
67
  else
65
68
  case @object
66
69
  when Date, Time, DateTime then string_stream
67
- when Integer, Float, String, Symbol, Array, Structure, Hash
70
+ when Integer, Float, String, Symbol, Array, Set, Structure, Hash
68
71
  send(@object.class.name.split('::').last.downcase + '_stream')
69
72
  end
70
73
  end
@@ -125,6 +128,8 @@ module Neo4j
125
128
  end.join
126
129
  end
127
130
 
131
+ alias set_stream array_stream
132
+
128
133
  def structure_stream
129
134
  fail 'Structure too big' if @object.list.size > 65_535
130
135
  marker_string(0xB0, 0xDC, @object.list.size) + [@object.signature].pack('C') + @object.list.map do |e|
@@ -252,7 +257,6 @@ module Neo4j
252
257
  Structure.new(shift_byte!, value_for_list!(size))
253
258
  end
254
259
 
255
-
256
260
  def shift_byte!
257
261
  shift_bytes!(1).first unless depleted?
258
262
  end
@@ -113,8 +113,7 @@ module Neo4j
113
113
  @engine ||= Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
114
114
  end
115
115
 
116
- def constraint_definitions_for(graph_db, label)
117
- end
116
+ def constraint_definitions_for(graph_db, label); end
118
117
  end
119
118
  end
120
119
  end
@@ -49,6 +49,10 @@ module Neo4j
49
49
  @uri = self.class.uri_from_url!(url)
50
50
  end
51
51
 
52
+ def url_without_password
53
+ @url_without_password ||= "#{scheme}://#{user + ':...@' if user}#{host}:#{port}"
54
+ end
55
+
52
56
  included do
53
57
  %w[scheme user password host port].each do |method|
54
58
  define_method(method) do
@@ -177,9 +177,7 @@ module Neo4j
177
177
  body_is_query_array = body.is_a?(Array) && body.all? { |o| o.respond_to?(:cypher) }
178
178
  case body
179
179
  when Hash, Array
180
- if body_is_query_array
181
- return {statements: body.map(&self.class.method(:statement_from_query))}
182
- end
180
+ return {statements: body.map(&self.class.method(:statement_from_query))} if body_is_query_array
183
181
 
184
182
  body
185
183
  else
@@ -28,7 +28,7 @@ module Neo4j
28
28
  when :proc
29
29
  yield.wrap
30
30
  else
31
- fail ArgumentError, "Inalid wrap_level: #{@wrap_level.inspect}"
31
+ fail ArgumentError, "Invalid wrap_level: #{@wrap_level.inspect}"
32
32
  end
33
33
  end
34
34
 
@@ -81,23 +81,6 @@ module Neo4j
81
81
  end
82
82
  end
83
83
 
84
- def wrap_by_level(none_value)
85
- case @wrap_level
86
- when :none
87
- if none_value.is_a?(Array)
88
- none_value.map(&:symbolize_keys)
89
- else
90
- none_value.symbolize_keys
91
- end
92
- when :core_entity
93
- yield
94
- when :proc
95
- yield.wrap
96
- else
97
- fail ArgumentError, "Invalid wrap_level: #{@wrap_level.inspect}"
98
- end
99
- end
100
-
101
84
  def wrap_node(id, labels, properties)
102
85
  wrap_by_level(properties) { ::Neo4j::Core::Node.new(id, labels, properties) }
103
86
  end
@@ -83,16 +83,18 @@ module Neo4j
83
83
  end
84
84
 
85
85
  def wrap_value(entity)
86
- if entity.is_a?(Java::ScalaCollectionConvert::Wrappers::MapWrapper)
86
+ case entity
87
+ when Java::ScalaCollectionConvert::Wrappers::MapWrapper
87
88
  entity.each_with_object({}) { |(k, v), r| r[k.to_sym] = _wrap_entity(v) }
88
- elsif entity.is_a?(Java::OrgNeo4jKernelImplCore::NodeProxy) ||
89
- entity.is_a?(Java::OrgNeo4jKernelImplCore::RelationshipProxy)
89
+ when Java::OrgNeo4jKernelImplCore::NodeProxy, Java::OrgNeo4jKernelImplCore::RelationshipProxy
90
90
  entity.property_keys.each_with_object({}) { |key, hash| hash[key.to_sym] = entity.get_property(key) }
91
- elsif entity.respond_to?(:path_entities) || entity.is_a?(Java::ScalaCollectionConvert::Wrappers::SeqWrapper)
92
- entity.to_a.map(&method(:_wrap_entity))
93
91
  else
94
- # Convert from Java?
95
- entity
92
+ if entity.respond_to?(:path_entities) || entity.is_a?(Java::ScalaCollectionConvert::Wrappers::SeqWrapper)
93
+ entity.to_a.map(&method(:_wrap_entity))
94
+ else
95
+ # Convert from Java?
96
+ entity.is_a?(Hash) ? entity.symbolize_keys : entity
97
+ end
96
98
  end
97
99
  end
98
100
 
@@ -29,12 +29,11 @@ module Neo4j
29
29
  end
30
30
 
31
31
  def wrap_entity(row_datum, rest_datum)
32
- case
33
- when rest_datum.is_a?(Array)
32
+ if rest_datum.is_a?(Array)
34
33
  row_datum.zip(rest_datum).map { |row, rest| wrap_entity(row, rest) }
35
- when ident = identify_entity(rest_datum)
34
+ elsif ident = identify_entity(rest_datum)
36
35
  send("wrap_#{ident}", rest_datum, row_datum)
37
- when rest_datum.is_a?(Hash)
36
+ elsif rest_datum.is_a?(Hash)
38
37
  rest_datum.each_with_object({}) do |(k, v), result|
39
38
  result[k.to_sym] = wrap_entity(row_datum[k], v)
40
39
  end
@@ -1,3 +1,5 @@
1
+ require 'neo4j/transaction'
2
+
1
3
  module Neo4j
2
4
  module Core
3
5
  class CypherSession
@@ -1,3 +1,4 @@
1
+ # TODO: Needed?
1
2
  module Neo4j
2
3
  module Core
3
4
  module TxMethods
@@ -13,19 +14,5 @@ module Neo4j
13
14
  end
14
15
  end
15
16
  end
16
-
17
- module Config
18
- def self.using_new_session?
19
- ENV.key?('NEW_NEO4J_SESSIONS')
20
- end
21
-
22
- def self.wrapping_level(level = nil)
23
- if level.nil?
24
- @wrapping_level || :core_entity
25
- else
26
- @wrapping_level = level
27
- end
28
- end
29
- end
30
17
  end
31
18
  end
@@ -0,0 +1,44 @@
1
+ # Copied largely from activerecord/lib/active_record/log_subscriber.rb
2
+ module Neo4j
3
+ module Core
4
+ module Logging
5
+ class << self
6
+ def first_external_path_and_line(callstack)
7
+ line = callstack.find do |frame|
8
+ frame.absolute_path && !ignored_callstack(frame.absolute_path)
9
+ end
10
+
11
+ offending_line = line || callstack.first
12
+
13
+ [offending_line.path,
14
+ offending_line.lineno]
15
+ end
16
+
17
+ NEO4J_CORE_GEM_ROOT = File.expand_path('../../..', __dir__) + '/'
18
+
19
+ def ignored_callstack(path)
20
+ paths_to_ignore.any?(&path.method(:start_with?))
21
+ end
22
+
23
+ def paths_to_ignore
24
+ @paths_to_ignore ||= [NEO4J_CORE_GEM_ROOT,
25
+ RbConfig::CONFIG['rubylibdir'],
26
+ neo4j_gem_path,
27
+ active_support_gem_path].compact
28
+ end
29
+
30
+ def neo4j_gem_path
31
+ return if !defined?(::Rails.root)
32
+
33
+ @neo4j_gem_path ||= File.expand_path('../../..', Neo4j::ActiveBase.method(:current_session).source_location[0])
34
+ end
35
+
36
+ def active_support_gem_path
37
+ return if !defined?(::ActiveSupport::Notifications)
38
+
39
+ @active_support_gem_path ||= File.expand_path('../../..', ActiveSupport::Notifications.method(:subscribe).source_location[0])
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,5 @@
1
- require 'neo4j-core/query_clauses'
1
+ require 'neo4j/core/query_clauses'
2
+ require 'neo4j/core/query_find_in_batches'
2
3
  require 'active_support/notifications'
3
4
 
4
5
  module Neo4j
@@ -67,7 +68,7 @@ module Neo4j
67
68
  end
68
69
 
69
70
  def initialize(options = {})
70
- @session = options.key?(:session) ? options[:session] : Neo4j::Session.current
71
+ @session = options[:session]
71
72
 
72
73
  @options = options
73
74
  @clauses = []
@@ -174,9 +175,9 @@ module Neo4j
174
175
 
175
176
  DEFINED_CLAUSES[clause.to_sym] = clause_class
176
177
  define_method(clause) do |*args|
177
- build_deeper_query(clause_class, args).ergo do |result|
178
- BREAK_METHODS.include?(clause) ? result.break : result
179
- end
178
+ result = build_deeper_query(clause_class, args)
179
+
180
+ BREAK_METHODS.include?(clause) ? result.break : result
180
181
  end
181
182
  end
182
183
 
@@ -201,7 +202,7 @@ module Neo4j
201
202
  # @example
202
203
  # # Creates a query representing the cypher: MATCH (n:Person) SET n.age = 19
203
204
  # Query.new.match(n: :Person).set_props(n: {age: 19})
204
- def set_props(*args)
205
+ def set_props(*args) # rubocop:disable Naming/AccessorMethodName
205
206
  build_deeper_query(SetClause, args, set_props: true)
206
207
  end
207
208
 
@@ -30,7 +30,7 @@ module Neo4j
30
30
 
31
31
  [String, Symbol, Integer, Hash, NilClass].each do |arg_class|
32
32
  from_method = "from_#{arg_class.name.downcase}"
33
- return @value = send(from_method, @arg) if @arg.is_a?(arg_class) && self.respond_to?(from_method)
33
+ return @value = send(from_method, @arg) if @arg.is_a?(arg_class) && respond_to?(from_method)
34
34
  end
35
35
 
36
36
  fail ArgError
@@ -42,12 +42,10 @@ module Neo4j
42
42
  end
43
43
 
44
44
  def from_hash(value)
45
- if self.respond_to?(:from_key_and_value)
46
- value.map do |k, v|
47
- from_key_and_value k, v
48
- end
49
- else
50
- fail ArgError
45
+ fail ArgError if !respond_to?(:from_key_and_value)
46
+
47
+ value.map do |k, v|
48
+ from_key_and_value k, v
51
49
  end
52
50
  end
53
51
 
@@ -64,9 +62,7 @@ module Neo4j
64
62
 
65
63
  prefix_value = value
66
64
  if value.is_a?(Hash)
67
- prefix_value = if value.values.any? { |v| v.is_a?(Hash) }
68
- value.keys.join(UNDERSCORE)
69
- end
65
+ prefix_value = (value.keys.join(UNDERSCORE) if value.values.any? { |v| v.is_a?(Hash) })
70
66
  end
71
67
 
72
68
  prefix_array = [key, prefix_value].tap(&:compact!).join(UNDERSCORE)
@@ -107,7 +103,6 @@ module Neo4j
107
103
  value.values.any? { |v| v.is_a?(Hash) }
108
104
  end
109
105
 
110
-
111
106
  def attributes_from_key_and_value(_key, value)
112
107
  return nil unless value.is_a?(Hash)
113
108
 
@@ -150,7 +145,7 @@ module Neo4j
150
145
  strings = clause_strings(clauses)
151
146
  stripped_string = strings.join(join_string)
152
147
  stripped_string.strip!
153
- (pretty && strings.size > 1) ? PRETTY_NEW_LINE + stripped_string : stripped_string
148
+ pretty && strings.size > 1 ? PRETTY_NEW_LINE + stripped_string : stripped_string
154
149
  end
155
150
 
156
151
  def clause_join
@@ -208,9 +203,7 @@ module Neo4j
208
203
  end
209
204
 
210
205
  def format_label(label_arg)
211
- if label_arg.is_a?(Array)
212
- return label_arg.map { |arg| format_label(arg) }.join
213
- end
206
+ return label_arg.map { |arg| format_label(arg) }.join if label_arg.is_a?(Array)
214
207
 
215
208
  label_arg = label_arg.to_s
216
209
  label_arg.strip!
@@ -552,7 +545,7 @@ module Neo4j
552
545
  from_string(value)
553
546
  end
554
547
 
555
- def from_nilclass(value)
548
+ def from_nilclass(_value)
556
549
  ''
557
550
  end
558
551
 
@@ -24,10 +24,8 @@ module Neo4j
24
24
  end
25
25
  end
26
26
 
27
- def find_each(*args)
28
- find_in_batches(*args) do |batch|
29
- batch.each { |result| yield result }
30
- end
27
+ def find_each(*args, &block)
28
+ find_in_batches(*args) { |batch| batch.each(&block) }
31
29
  end
32
30
 
33
31
  private
@@ -41,7 +39,7 @@ module Neo4j
41
39
  last_record.send(node_var).send(prop_var)
42
40
  rescue NoMethodError
43
41
  begin
44
- last_record.send(node_var)[prop_var.to_sym]
42
+ last_record.send(node_var).properties[prop_var.to_sym]
45
43
  rescue NoMethodError
46
44
  last_record.send("#{node_var}.#{prop_var}") # In case we're explicitly returning it
47
45
  end
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = '8.1.4'
3
+ VERSION = '9.0.0.alpha.1'
4
4
  end
5
5
  end
@@ -145,17 +145,15 @@ module Neo4j
145
145
  # To support old syntax of providing run_in_tx first
146
146
  # But session first is ideal
147
147
  def session_and_run_in_tx_from_args(args)
148
+ fail ArgumentError, 'Too few arguments' if args.empty?
148
149
  fail ArgumentError, 'Too many arguments' if args.size > 2
149
150
 
150
- if args.empty?
151
- [Session.current!, true]
152
- else
153
- result = args.dup
154
- if result.size == 1
155
- result << ([true, false].include?(args[0]) ? Session.current! : true)
156
- end
151
+ if args.size == 1
152
+ fail ArgumentError, 'Session must be specified' if !args[0].is_a?(Neo4j::Core::CypherSession)
157
153
 
158
- [true, false].include?(result[0]) ? result.reverse : result
154
+ [args[0], true]
155
+ else
156
+ [true, false].include?(args[0]) ? args.reverse : args.dup
159
157
  end
160
158
  end
161
159
 
@@ -1,12 +1,12 @@
1
- lib = File.expand_path('../lib/', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'neo4j-core/version'
4
+ require 'neo4j/core/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'neo4j-core'
8
8
  s.version = Neo4j::Core::VERSION
9
- s.required_ruby_version = '>= 1.9.3'
9
+ s.required_ruby_version = '>= 2.1.0'
10
10
 
11
11
  s.authors = 'Andreas Ronge, Chris Grigg, Brian Underwood'
12
12
  s.email = 'andreas.ronge@gmail.com, chris@subvertallmedia.com, brian@brian-underwood.codes'
@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
14
14
  s.summary = 'A basic library to work with the graph database Neo4j.'
15
15
  s.license = 'MIT'
16
16
 
17
- s.description = <<-EOF
18
- Neo4j-core provides classes and methods to work with the graph database Neo4j.
19
- EOF
17
+ s.description = <<-DESCRIPTION
18
+ Neo4j-core provides classes and methods to work with the graph database Neo4j.
19
+ DESCRIPTION
20
20
 
21
21
  s.require_path = 'lib'
22
22
  s.files = Dir.glob('{bin,lib,config}/**/*') + %w[README.md Gemfile neo4j-core.gemspec]
@@ -38,19 +38,21 @@ Neo4j-core provides classes and methods to work with the graph database Neo4j.
38
38
  s.add_dependency('httpclient')
39
39
  s.add_dependency('json')
40
40
  s.add_dependency('multi_json')
41
+ s.add_dependency('net_tcp_client', '>= 2.0.1')
41
42
  s.add_dependency('typhoeus', '>= 1.1.2')
42
43
 
44
+ s.add_development_dependency('dryspec')
43
45
  s.add_development_dependency('neo4j-rake_tasks', '>= 0.3.0')
44
46
  s.add_development_dependency('pry')
45
47
  s.add_development_dependency('simplecov')
46
48
  s.add_development_dependency('yard')
47
49
 
48
50
  if RUBY_PLATFORM == 'java'
49
- s.add_dependency('neo4j-community', '>= 2.1.1')
51
+ s.add_development_dependency('neo4j-community', '>= 2.1.1')
50
52
  s.add_development_dependency 'ruby-debug'
51
- else
52
- s.add_development_dependency('guard')
53
- s.add_development_dependency('guard-rubocop')
54
- s.add_development_dependency('rubocop', '~> 0.49.1')
55
53
  end
54
+
55
+ s.add_development_dependency('guard')
56
+ s.add_development_dependency('guard-rubocop')
57
+ s.add_development_dependency('rubocop', '~> 0.56.0')
56
58
  end