neo4j-core 3.0.0.alpha.9 → 3.0.0.alpha.10

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: 603fa5b52e151a255cb6af0c99ee8a13442cfb58
4
- data.tar.gz: c2045779a04c9d9680ed3ff4ff811f5f6f42ba3d
3
+ metadata.gz: 8a84afded3b491b86251ab1b129c8722e921fd0b
4
+ data.tar.gz: c2db2be7dfdf1cf1dc33f5a13d43c3083b24e46d
5
5
  SHA512:
6
- metadata.gz: 5f26e769116c75daa0666eb77a2278c59e36652f195d2c4b81dcba47b5837028e216d30c8c1fb55fa096791c14f63da78dce00464eee059bc803c4ab4598655d
7
- data.tar.gz: 0fcf3a37a9833e1c6d37d24173e8c895536a0f2cc0ea3e0201452b8f27a89038854481ece391016e6d66159b67d5d100c257837321549b76c254a475a346ca25
6
+ metadata.gz: fd6fccc4a3ba5c2980b0ed478d65d5a2389f1da43f24540fd5e823fdf91b5b7a5cd1148a6f0049b5f4c3db698617235a40ce52aea7da2d81c9e263b0b9231a76
7
+ data.tar.gz: 22ad54611e1d5d896f94e5d47265c08e9dd27dd26132f7e9b9262eb4097a01e2030f2ebb806636c1d6c20999d2751291225c548f54e6ad999ac989982a82532d
@@ -1,14 +1,38 @@
1
1
  module Neo4j::Core
2
2
  module CypherTranslator
3
3
  # Cypher Helper
4
- def escape_value(value)
5
- case value
6
- when String
7
- "'#{value.gsub("'", %q(\\\'))}'"
8
- else
9
- value
10
- end
11
- end
4
+ def escape_value(value)
5
+ result = case value
6
+ when String
7
+ sanitized = sanitize_escape_sequences(value)
8
+ "'#{escape_quotes(sanitized)}'"
9
+ else
10
+ value
11
+ end
12
+ result
13
+ end
14
+
15
+ # Only following escape sequence characters are allowed in Cypher:
16
+ #
17
+ # \t Tab
18
+ # \b Backspace
19
+ # \n Newline
20
+ # \r Carriage return
21
+ # \f Form feed
22
+ # \' Single quote
23
+ # \" Double quote
24
+ # \\ Backslash
25
+ #
26
+ # From:
27
+ # http://docs.neo4j.org/chunked/stable/cypher-expressions.html#_note_on_string_literals
28
+ SANITIZE_ESCAPED_REGEXP = /(?<!\\)\\(\\\\)*(?![futbnr'"\\])/
29
+ def sanitize_escape_sequences(s)
30
+ s.gsub SANITIZE_ESCAPED_REGEXP, ''
31
+ end
32
+
33
+ def escape_quotes(s)
34
+ s.gsub("'", %q(\\\'))
35
+ end
12
36
 
13
37
  # Cypher Helper
14
38
  def cypher_prop_list(props)
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = "3.0.0.alpha.9"
3
+ VERSION = "3.0.0.alpha.10"
4
4
  end
5
5
  end
@@ -35,7 +35,11 @@ module Neo4j::Embedded::Property
35
35
 
36
36
  def _update_props(hash)
37
37
  hash.each_pair do |k,v|
38
- set_property(k,v)
38
+ if v.nil?
39
+ remove_property(k)
40
+ else
41
+ set_property(k,v)
42
+ end
39
43
  end
40
44
  hash
41
45
  end
@@ -51,10 +51,22 @@ module Neo4j::Server
51
51
  properties
52
52
  end
53
53
 
54
+ def remove_properties(properties)
55
+ q = "START n=node(#{neo_id}) REMOVE " + properties.map do |k|
56
+ "n.`#{k}`"
57
+ end.join(', ')
58
+ @session._query_or_fail(q)
59
+ end
60
+
54
61
  # (see Neo4j::Node#update_props)
55
62
  def update_props(properties)
56
63
  return if properties.empty?
57
- q = "START n=node(#{neo_id}) SET " + properties.keys.map do |k|
64
+
65
+ removed_keys = properties.keys.select{|k| properties[k].nil?}
66
+ remove_properties(removed_keys) unless removed_keys.empty?
67
+ properties_to_set = properties.keys - removed_keys
68
+ return if properties_to_set.empty?
69
+ q = "START n=node(#{neo_id}) SET " + properties_to_set.map do |k|
58
70
  "n.`#{k}`= #{escape_value(properties[k])}"
59
71
  end.join(',')
60
72
  @session._query_or_fail(q)
@@ -5,7 +5,9 @@ module Neo4j::Server
5
5
  response = HTTParty.get(endpoint_url || 'http://localhost:7474')
6
6
  raise "Server not available on #{endpoint_url} (response code #{response.code})" unless response.code == 200
7
7
  root_data = JSON.parse(response.body)
8
- Neo4j::Server::CypherSession.new(root_data['data'])
8
+ data_url = root_data['data']
9
+ data_url << '/' unless data_url.end_with?('/')
10
+ Neo4j::Server::CypherSession.new(data_url)
9
11
  end
10
12
 
11
13
  class CypherSession < Neo4j::Session
@@ -36,7 +36,7 @@ module Neo4j::Server
36
36
 
37
37
  # So we have to do this workaround
38
38
  params.each_pair do |k,v|
39
- statement[:statement].gsub!("{ #{k} }", escape_value(v))
39
+ statement[:statement].gsub!("{ #{k} }", "#{escape_value(v)}")
40
40
  end
41
41
  end
42
42
  response = HTTParty.post(@exec_url, headers: resource_headers, body: body.to_json)
data/lib/neo4j/session.rb CHANGED
@@ -50,23 +50,23 @@ module Neo4j
50
50
  # Returns an enumerable of hash values, column => value
51
51
  #
52
52
  # @example Using the Cypher DSL
53
- # q = Neo4j.query("START n=node({param}) RETURN n", :param => 0)
53
+ # q = session.query("START n=node({param}) RETURN n", :param => 0)
54
54
  # q.first[:n] #=> the node
55
55
  # q.columns.first => :n
56
56
  #
57
57
  # @example Using the Cypher DSL
58
- # q = Neo4j.query{ match node(3) <=> node(:x); ret :x}
58
+ # q = session.query{ match node(3) <=> node(:x); ret :x}
59
59
  # q.first[:n] #=> the @node
60
60
  # q.columns.first => :n
61
61
  #
62
62
  # @example Using the Cypher DSL and one parameter (n=Neo4j.ref_node)
63
- # q = Neo4j.query(Neo4j.ref_node){|n| n <=> node(:x); :x}
63
+ # q = session.query(Neo4j.ref_node){|n| n <=> node(:x); :x}
64
64
  # q.first[:n] #=> the @node
65
65
  # q.columns.first => :n
66
66
  #
67
67
  # @example Using an array of nodes
68
68
  # # same as - two_nodes=node(Neo4j.ref_node.neo_id, node_b.neo_id), b = node(b.neo_id)
69
- # q = Neo4j.query([Neo4j.ref_node, node_b], node_c){|two_nodes, b| two_nodes <=> b; b}
69
+ # q = session.query([Neo4j.ref_node, node_b], node_c){|two_nodes, b| two_nodes <=> b; b}
70
70
  #
71
71
  # @see Cypher
72
72
  # @see http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html The Cypher Query Language Documentation
@@ -100,7 +100,7 @@ module Neo4j
100
100
  register(create_session(db_type, params), name, default)
101
101
  end
102
102
 
103
- def create_session(db_type, params)
103
+ def create_session(db_type, params = {})
104
104
  unless (@@factories[db_type])
105
105
  raise "Can't connect to database '#{db_type}', available #{@@factories.keys.join(',')}"
106
106
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.9
4
+ version: 3.0.0.alpha.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-08 00:00:00.000000000 Z
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: os
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: neo4j-cypher
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: |
@@ -77,21 +77,15 @@ extensions: []
77
77
  extra_rdoc_files:
78
78
  - README.md
79
79
  files:
80
- - lib/neo4j/entity_equality.rb
81
- - lib/neo4j/label.rb
82
- - lib/neo4j/node.rb
83
- - lib/neo4j/property_container.rb
84
- - lib/neo4j/property_validator.rb
85
- - lib/neo4j/relationship.rb
86
- - lib/neo4j/session.rb
87
- - lib/neo4j/tasks/neo4j_server.rb
88
- - lib/neo4j/transaction.rb
80
+ - Gemfile
81
+ - README.md
82
+ - lib/neo4j-core.rb
89
83
  - lib/neo4j-core/cypher_translator.rb
90
84
  - lib/neo4j-core/hash_with_indifferent_access.rb
91
85
  - lib/neo4j-core/helpers.rb
92
86
  - lib/neo4j-core/label.rb
93
87
  - lib/neo4j-core/version.rb
94
- - lib/neo4j-core.rb
88
+ - lib/neo4j-embedded.rb
95
89
  - lib/neo4j-embedded/embedded_database.rb
96
90
  - lib/neo4j-embedded/embedded_impermanent_session.rb
97
91
  - lib/neo4j-embedded/embedded_label.rb
@@ -100,7 +94,7 @@ files:
100
94
  - lib/neo4j-embedded/embedded_session.rb
101
95
  - lib/neo4j-embedded/property.rb
102
96
  - lib/neo4j-embedded/to_java.rb
103
- - lib/neo4j-embedded.rb
97
+ - lib/neo4j-server.rb
104
98
  - lib/neo4j-server/cypher_label.rb
105
99
  - lib/neo4j-server/cypher_node.rb
106
100
  - lib/neo4j-server/cypher_node_uncommited.rb
@@ -109,38 +103,43 @@ files:
109
103
  - lib/neo4j-server/cypher_session.rb
110
104
  - lib/neo4j-server/cypher_transaction.rb
111
105
  - lib/neo4j-server/resource.rb
112
- - lib/neo4j-server.rb
113
- - lib/test.rb
114
- - README.md
115
- - Gemfile
106
+ - lib/neo4j/entity_equality.rb
107
+ - lib/neo4j/label.rb
108
+ - lib/neo4j/node.rb
109
+ - lib/neo4j/property_container.rb
110
+ - lib/neo4j/property_validator.rb
111
+ - lib/neo4j/relationship.rb
112
+ - lib/neo4j/session.rb
113
+ - lib/neo4j/tasks/neo4j_server.rb
114
+ - lib/neo4j/transaction.rb
116
115
  - neo4j-core.gemspec
117
116
  homepage: http://github.com/andreasronge/neo4j-core/tree
118
117
  licenses: []
119
118
  metadata: {}
120
119
  post_install_message:
121
120
  rdoc_options:
122
- - --quiet
123
- - --title
121
+ - "--quiet"
122
+ - "--title"
124
123
  - Neo4j::Core
125
- - --line-numbers
126
- - --main
124
+ - "--line-numbers"
125
+ - "--main"
127
126
  - README.rdoc
128
- - --inline-source
127
+ - "--inline-source"
129
128
  require_paths:
130
129
  - lib
131
130
  required_ruby_version: !ruby/object:Gem::Requirement
132
131
  requirements:
133
- - - '>='
132
+ - - ">="
134
133
  - !ruby/object:Gem::Version
135
134
  version: 1.8.7
136
135
  required_rubygems_version: !ruby/object:Gem::Requirement
137
136
  requirements:
138
- - - '>'
137
+ - - ">"
139
138
  - !ruby/object:Gem::Version
140
139
  version: 1.3.1
141
140
  requirements: []
142
141
  rubyforge_project: neo4j-core
143
- rubygems_version: 2.1.5
142
+ rubygems_version: 2.2.2
144
143
  signing_key:
145
144
  specification_version: 4
146
145
  summary: A graph database for JRuby
data/lib/test.rb DELETED
@@ -1,11 +0,0 @@
1
- class Hej
2
- attr_accessor :values
3
-
4
- def []=(key, v)
5
- self.values = *v
6
- end
7
- end
8
-
9
- h = Hej.new
10
- h[:koo] = 1
11
- puts "h: #{h.values.inspect}"