neography 1.2.3 → 1.2.4

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: 02984a89ccb8239cc1512ec697d742953aef36f7
4
- data.tar.gz: c97a3fdfb802c83754ac35d127eeb571378974d7
3
+ metadata.gz: fcd694c03de5bbb920692ee87085c2da39815c2b
4
+ data.tar.gz: 27cac259abff49d847b099819c6c5bd7f617f69f
5
5
  SHA512:
6
- metadata.gz: 32d3b4de20035dca8f58762969fdd336ce64307d549ea14e43ae83ea011f1ce3bdd3f8093bb1b11ceb9ebafaca11375ebbc68fa1880de4851d80fcff50bdc9d7
7
- data.tar.gz: 301c1d21db5b478d5fda1c3f6792a0848f2dc7403973a1a0ce228b8a60b1c3594fde81c1a3d60295b49e2511a55f7715b67d6609f1f8b9b1622ff420a0258ecf
6
+ metadata.gz: 31203feeec0907870e2be162a47f201c78a1ab5e306119e6dd018ed711365f35b9580d87b48bfdb842b4e1f003162db2e2bf2b4bfa65ef9f1ad72a030ecd1e23
7
+ data.tar.gz: 79270c702fb7e25a6c9a8a2858dc510dbad1c60a333df6ecc2e7105c431ecee60be0371bba1c6c12ac9c755f511e772e19ea9b76e0c1f5952f34b250711c017e
@@ -40,11 +40,27 @@ module Neography
40
40
 
41
41
  ACTIONS.each do |action|
42
42
  define_method(action) do |path, options = {}|
43
- authenticate(configuration + path)
44
- evaluate_response(@client.send(action.to_sym, configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
43
+ query_path = configuration + path
44
+ query_body = merge_options(options)[:body]
45
+ authenticate(query_path)
46
+ log path, query_body do
47
+ evaluate_response(@client.send(action.to_sym, query_path, query_body, merge_options(options)[:headers]))
48
+ end
45
49
  end
46
50
  end
47
51
 
52
+ def log(path, body)
53
+ if @log_enabled
54
+ start_time = Time.now
55
+ response = yield
56
+ time = ((Time.now - start_time) * 1000).round(2)
57
+ @logger.info "[Neography::Query] #{path} #{body} [#{time}ms]"
58
+ response
59
+ else
60
+ yield
61
+ end
62
+ end
63
+
48
64
  def authenticate(path)
49
65
  @client.set_auth(path,
50
66
  @authentication[@authentication.keys.first][:username],
@@ -17,6 +17,14 @@ module Neography
17
17
  node
18
18
  end
19
19
 
20
+ def create_unique(index, key, value, props = nil, db = Neography::Rest.new)
21
+ raise ArgumentError.new("syntax deprecated") if props.is_a?(Neography::Rest)
22
+
23
+ node = self.new(db.create_unique_node(index, key, value, props))
24
+ node.neo_server = db
25
+ node
26
+ end
27
+
20
28
  def load(node, db = Neography::Rest.new)
21
29
  raise ArgumentError.new("syntax deprecated") if node.is_a?(Neography::Rest)
22
30
  node = node.first if node.kind_of?(Array)
@@ -16,6 +16,14 @@ module Neography
16
16
  rel
17
17
  end
18
18
 
19
+ def create_unique(index, key, value, type, from_node, to_node, props = nil)
20
+ rel = Neography::Relationship.new(from_node.neo_server.create_unique_relationship(index, key, value, type, from_node, to_node, props))
21
+ rel.start_node = from_node
22
+ rel.end_node = to_node
23
+ rel.rel_type = type
24
+ rel
25
+ end
26
+
19
27
  def load(rel, db = Neography::Rest.new)
20
28
  raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest)
21
29
 
@@ -347,8 +347,8 @@ module Neography
347
347
  @relationship_indexes.create_auto(type, provider)
348
348
  end
349
349
 
350
- def create_unique_relationship(index, key, value, type, from, to)
351
- @relationship_indexes.create_unique(index, key, value, type, from, to)
350
+ def create_unique_relationship(index, key, value, type, from, to, props = nil)
351
+ @relationship_indexes.create_unique(index, key, value, type, from, to, props)
352
352
  end
353
353
 
354
354
  def add_relationship_to_index(index, key, value, id)
@@ -54,6 +54,21 @@ module Neography
54
54
 
55
55
  # NodeIndexes
56
56
 
57
+ def create_node_index(name, type = "exact", provider = "lucene")
58
+ post NodeIndexes.all_path do
59
+ { :name => name,
60
+ :config => {
61
+ :type => type,
62
+ :provider => provider
63
+ }
64
+ }
65
+ end
66
+ end
67
+
68
+ def drop_node_index(index)
69
+ delete NodeIndexes.unique_path(:index => index)
70
+ end
71
+
57
72
  def create_unique_node(index, key, value, properties)
58
73
  post NodeIndexes.unique_path(:index => index) do
59
74
  {
@@ -17,13 +17,14 @@ module Neography
17
17
  super(connection, :relationship)
18
18
  end
19
19
 
20
- def create_unique(index, key, value, type, from, to)
20
+ def create_unique(index, key, value, type, from, to, props = nil)
21
21
  body = {
22
22
  :key => key,
23
23
  :value => value,
24
24
  :type => type,
25
25
  :start => @connection.configuration + "/node/#{get_id(from)}",
26
- :end => @connection.configuration + "/node/#{get_id(to)}"
26
+ :end => @connection.configuration + "/node/#{get_id(to)}",
27
+ :properties => props
27
28
  }
28
29
  options = { :body => body.to_json, :headers => json_content_type }
29
30
 
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -210,6 +210,23 @@ describe Neography::Rest do
210
210
  existing_relationship["self"].should == new_relationship["self"]
211
211
  end
212
212
 
213
+ it "can drop a node index" do
214
+ index_name = generate_text(6)
215
+ @neo.create_node_index(index_name)
216
+ @neo.batch [:drop_node_index, index_name]
217
+ @neo.list_node_indexes[index_name].should be_nil
218
+ end
219
+
220
+ it "can create a node index" do
221
+ index_name = generate_text(6)
222
+ @neo.batch [:create_node_index, index_name, "fulltext", "lucene"]
223
+ indexes = @neo.list_node_indexes
224
+ index = indexes[index_name]
225
+ index.should_not be_nil
226
+ index["provider"].should == "lucene"
227
+ index["type"].should == "fulltext"
228
+ end
229
+
213
230
  it "can add a node to an index" do
214
231
  index_name = generate_text(6)
215
232
  new_node = @neo.create_node
@@ -204,6 +204,31 @@ module Neography
204
204
  end
205
205
 
206
206
  end
207
+
208
+ context "query logging" do
209
+ before do
210
+ connection.logger = Logger.new(nil)
211
+ connection.log_enabled = true
212
+ end
213
+
214
+ let :expected_response do
215
+ "expected_response"
216
+ end
217
+
218
+ let :request_body do
219
+ {key1: :val1}
220
+ end
221
+
222
+ it "should log query" do
223
+ connection.should_receive(:log).with("/foo/bar", request_body).once
224
+ connection.get("/foo/bar", {body: request_body})
225
+ end
226
+
227
+ it "should return original response" do
228
+ connection.stub(:evaluate_response).and_return expected_response
229
+ connection.get("/foo/bar").should eq expected_response
230
+ end
231
+ end
207
232
  end
208
233
  end
209
234
  end
@@ -47,10 +47,11 @@ module Neography
47
47
  "value" => "value",
48
48
  "type" => "type",
49
49
  "start" => "http://configuration/node/42",
50
- "end" => "http://configuration/node/43"
50
+ "end" => "http://configuration/node/43",
51
+ "properties" => "properties"
51
52
  }
52
53
  connection.should_receive(:post).with("/index/relationship/some_index?unique", json_match(:body, expected_body))
53
- subject.create_unique("some_index", "key", "value", "type", "42", "43")
54
+ subject.create_unique("some_index", "key", "value", "type", "42", "43", "properties")
54
55
  end
55
56
 
56
57
  it "adds a relationship to an index" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max De Marzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-30 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec