neo4j-core 4.0.7 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ module Neo4j
2
+ class Label
3
+ class << self
4
+ def constraints(session = Neo4j::Session.current)
5
+ session.connection.get(CONSTRAINT_PATH).body
6
+ end
7
+
8
+ def constraint?(label_name, property, session = Neo4j::Session.current)
9
+ label_constraints = session.connection.get("#{CONSTRAINT_PATH}/#{label_name}").body
10
+ !label_constraints.select { |c| c[:label] == label_name.to_s && c[:property_keys].first == property.to_s }.empty?
11
+ end
12
+
13
+ def indexes(session = Neo4j::Session.current)
14
+ session.connection.get(INDEX_PATH).body
15
+ end
16
+
17
+ def index?(label_name, property, session = Neo4j::Session.current)
18
+ label_indexes = session.connection.get("#{INDEX_PATH}/#{label_name}").body
19
+ !label_indexes.select { |i| i[:label] == label_name.to_s && i[:property_keys].first == property.to_s }.empty?
20
+ end
21
+
22
+ def drop_all_indexes(session = Neo4j::Session.current)
23
+ indexes.each do |i|
24
+ begin
25
+ session._query_or_fail("DROP INDEX ON :`#{i[:label]}`(#{i[:property_keys].first})")
26
+ rescue Neo4j::Server::CypherResponse::ResponseError
27
+ # This will error on each constraint. Ignore and continue.
28
+ next
29
+ end
30
+ end
31
+ end
32
+
33
+ def drop_all_constraints(session = Neo4j::Session.current)
34
+ constraints.each do |c|
35
+ session._query_or_fail("DROP CONSTRAINT ON (n:`#{c[:label]}`) ASSERT n.`#{c[:property_keys].first}` IS UNIQUE")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -7,44 +7,43 @@ module Neo4j
7
7
  attr_reader :resource_data, :resource_url
8
8
 
9
9
  def init_resource_data(resource_data, resource_url)
10
- fail "Exception #{resource_data['exception']}" if resource_data['exception']
10
+ fail "Exception #{resource_data[:exception]}" if resource_data[:exception]
11
11
  fail "Expected @resource_data to be Hash got #{resource_data.inspect}" unless resource_data.respond_to?(:[])
12
12
 
13
- @resource_url = resource_url
14
13
  @resource_data = resource_data
14
+ @resource_url = resource_url
15
15
 
16
16
  self
17
17
  end
18
18
 
19
19
  def wrap_resource(connection = Neo4j::Session.current)
20
- url = resource_url('transaction')
20
+ url = resource_url(:transaction)
21
21
  CypherTransaction.new(url, connection)
22
22
  end
23
23
 
24
24
  def resource_url(key = nil)
25
25
  return @resource_url if key.nil?
26
-
27
- @resource_data.fetch key.to_s
26
+ @resource_data.fetch key
28
27
  rescue KeyError
29
28
  raise "No resource key '#{key}', available #{@resource_data.keys.inspect}"
30
29
  end
31
30
 
32
- def handle_response_error(response, msg = 'Error for request')
33
- fail ServerException, "#{msg} #{response.env && response.env[:url].to_s}, #{response.status}, #{response.status}"
31
+ def expect_response_code!(response, expected_code, msg = 'Error for request')
32
+ handle_response_error!(response, "Expected response code #{expected_code} #{msg}") unless response.status == expected_code
33
+ response
34
34
  end
35
35
 
36
- def expect_response_code(response, expected_code, msg = 'Error for request')
37
- handle_response_error(response, "Expected response code #{expected_code} #{msg}") unless response.status == expected_code
38
- response
36
+ def handle_response_error!(response, msg = 'Error for request')
37
+ fail ServerException, "#{msg} #{response.env && response.env[:url].to_s}, #{response.status}"
39
38
  end
40
39
 
41
40
  def response_exception(response)
42
41
  return nil if response.body.nil? || response.body.empty?
43
- JSON.parse(response.body)['exception']
42
+ JSON.parse(response.body)[:exception]
44
43
  end
45
44
 
46
45
  def resource_headers
47
- {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string}
46
+ {'Content-Type' => 'application/json', 'Accept' => 'application/json; charset=UTF-8', 'User-Agent' => ::Neo4j::Session.user_agent_string}
48
47
  end
49
48
 
50
49
  def resource_url_id(url = resource_url)
data/lib/neo4j-server.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
3
  require 'faraday_middleware'
4
+ require 'faraday_middleware/multi_json'
4
5
  require 'neo4j-server/resource'
5
6
  require 'neo4j-server/cypher_node'
6
7
  require 'neo4j-server/cypher_label'
8
+ require 'neo4j-server/label'
7
9
  require 'neo4j-server/cypher_session'
8
10
  require 'neo4j-server/cypher_node_uncommited'
9
11
  require 'neo4j-server/cypher_relationship'
data/neo4j-core.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'neo4j-core/version'
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.0.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'
@@ -33,12 +33,15 @@ Neo4j-core provides classes and methods to work with the graph database Neo4j.
33
33
  s.add_dependency('os') # for Rake task
34
34
  s.add_dependency('zip') # for Rake task
35
35
  s.add_dependency('activesupport') # For ActiveSupport::Notifications
36
+ s.add_dependency('multi_json')
37
+ s.add_dependency('faraday_middleware-multi_json')
36
38
 
37
39
  s.add_development_dependency('pry')
38
40
  s.add_development_dependency('yard')
39
41
  s.add_development_dependency('simplecov')
40
42
  s.add_development_dependency('guard')
41
43
  s.add_development_dependency('guard-rubocop')
44
+ s.add_development_dependency('rubocop', '~> 0.29.1')
42
45
 
43
46
  if RUBY_PLATFORM == 'java'
44
47
  s.add_dependency('neo4j-community', '>= 2.1.1')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.7
4
+ version: 5.0.0.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Chris Grigg, Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: multi_json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: faraday_middleware-multi_json
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: pry
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +234,20 @@ dependencies:
206
234
  - - ">="
207
235
  - !ruby/object:Gem::Version
208
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rubocop
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.29.1
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.29.1
209
251
  description: |
210
252
  Neo4j-core provides classes and methods to work with the graph database Neo4j.
211
253
  email: andreas.ronge@gmail.com, chris@subvertallmedia.com, brian@brian-underwood.codes
@@ -216,10 +258,10 @@ extra_rdoc_files:
216
258
  files:
217
259
  - Gemfile
218
260
  - README.md
261
+ - lib/ext/kernel.rb
219
262
  - lib/neo4j-core.rb
220
263
  - lib/neo4j-core/active_entity.rb
221
264
  - lib/neo4j-core/cypher_translator.rb
222
- - lib/neo4j-core/graph_json.rb
223
265
  - lib/neo4j-core/hash_with_indifferent_access.rb
224
266
  - lib/neo4j-core/helpers.rb
225
267
  - lib/neo4j-core/label.rb
@@ -237,6 +279,7 @@ files:
237
279
  - lib/neo4j-embedded/embedded_relationship.rb
238
280
  - lib/neo4j-embedded/embedded_session.rb
239
281
  - lib/neo4j-embedded/embedded_transaction.rb
282
+ - lib/neo4j-embedded/label.rb
240
283
  - lib/neo4j-embedded/property.rb
241
284
  - lib/neo4j-embedded/to_java.rb
242
285
  - lib/neo4j-server.rb
@@ -247,6 +290,7 @@ files:
247
290
  - lib/neo4j-server/cypher_response.rb
248
291
  - lib/neo4j-server/cypher_session.rb
249
292
  - lib/neo4j-server/cypher_transaction.rb
293
+ - lib/neo4j-server/label.rb
250
294
  - lib/neo4j-server/resource.rb
251
295
  - lib/neo4j/entity_equality.rb
252
296
  - lib/neo4j/label.rb
@@ -278,12 +322,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
322
  requirements:
279
323
  - - ">="
280
324
  - !ruby/object:Gem::Version
281
- version: 1.9.3
325
+ version: 2.0.0
282
326
  required_rubygems_version: !ruby/object:Gem::Requirement
283
327
  requirements:
284
- - - ">="
328
+ - - ">"
285
329
  - !ruby/object:Gem::Version
286
- version: '0'
330
+ version: 1.3.1
287
331
  requirements: []
288
332
  rubyforge_project:
289
333
  rubygems_version: 2.4.5
@@ -1,35 +0,0 @@
1
- module Neo4j
2
- module Core
3
- module GraphJSON
4
- def self.to_graph_json(objects)
5
- nodes = {}
6
- edges = {}
7
-
8
- objects.each do |object|
9
- case object
10
- when Neo4j::ActiveNode, Neo4j::Server::CypherNode
11
- nodes[object.neo_id] = {
12
- id: object.neo_id,
13
- labels: (object.is_a?(Neo4j::ActiveNode) ? [object.class.name] : object.labels),
14
- properties: object.attributes
15
- }
16
- when Neo4j::ActiveRel, Neo4j::Server::CypherRelationship
17
- edges[[object.start_node.neo_id, object.end_node.neo_id]] = {
18
- source: object.start_node.neo_id,
19
- target: object.end_node.neo_id,
20
- type: object.rel_type,
21
- properties: object.props
22
- }
23
- else
24
- fail "Invalid value found: #{object.inspect}"
25
- end
26
- end
27
-
28
- {
29
- nodes: nodes.values,
30
- edges: edges.values
31
- }.to_json
32
- end
33
- end
34
- end
35
- end