neography 1.3.14 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neography/rest.rb +29 -472
- data/lib/neography/rest/batch.rb +80 -87
- data/lib/neography/rest/clean.rb +8 -10
- data/lib/neography/rest/constraints.rb +15 -25
- data/lib/neography/rest/cypher.rb +2 -6
- data/lib/neography/rest/extensions.rb +4 -8
- data/lib/neography/rest/gremlin.rb +2 -6
- data/lib/neography/rest/helpers.rb +58 -0
- data/lib/neography/rest/node_auto_indexes.rb +54 -8
- data/lib/neography/rest/node_indexes.rb +92 -17
- data/lib/neography/rest/node_labels.rb +15 -26
- data/lib/neography/rest/node_paths.rb +8 -16
- data/lib/neography/rest/node_properties.rb +45 -4
- data/lib/neography/rest/node_relationships.rb +8 -17
- data/lib/neography/rest/node_traversal.rb +7 -63
- data/lib/neography/rest/nodes.rb +21 -29
- data/lib/neography/rest/other_node_relationships.rb +6 -13
- data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
- data/lib/neography/rest/relationship_indexes.rb +104 -14
- data/lib/neography/rest/relationship_properties.rb +45 -4
- data/lib/neography/rest/relationship_types.rb +4 -11
- data/lib/neography/rest/relationships.rb +6 -13
- data/lib/neography/rest/schema_indexes.rb +8 -16
- data/lib/neography/rest/spatial.rb +16 -33
- data/lib/neography/rest/transactions.rb +25 -26
- data/lib/neography/tasks.rb +2 -2
- data/lib/neography/version.rb +1 -1
- data/spec/unit/rest/batch_spec.rb +49 -50
- data/spec/unit/rest/clean_spec.rb +3 -4
- data/spec/unit/rest/constraints_spec.rb +12 -13
- data/spec/unit/rest/cypher_spec.rb +3 -4
- data/spec/unit/rest/extensions_spec.rb +5 -6
- data/spec/unit/rest/gremlin_spec.rb +5 -6
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +21 -22
- data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/node_indexes_spec.rb +42 -43
- data/spec/unit/rest/node_paths_spec.rb +10 -13
- data/spec/unit/rest/node_properties_spec.rb +22 -23
- data/spec/unit/rest/node_relationships_spec.rb +18 -39
- data/spec/unit/rest/node_traversal_spec.rb +4 -97
- data/spec/unit/rest/nodes_spec.rb +47 -48
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
- data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
- data/spec/unit/rest/relationship_properties_spec.rb +22 -23
- data/spec/unit/rest/relationship_types_spec.rb +3 -4
- data/spec/unit/rest/relationships_spec.rb +5 -6
- data/spec/unit/rest/schema_index_spec.rb +7 -8
- data/spec/unit/rest/transactions_spec.rb +10 -11
- metadata +27 -31
- data/lib/neography/rest/auto_indexes.rb +0 -64
- data/lib/neography/rest/indexes.rb +0 -102
- data/lib/neography/rest/paths.rb +0 -46
- data/lib/neography/rest/properties.rb +0 -56
- data/spec/unit/rest/paths_spec.rb +0 -69
data/lib/neography/rest/paths.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Neography
|
2
|
-
class Rest
|
3
|
-
module Paths
|
4
|
-
|
5
|
-
def add_path(key, path)
|
6
|
-
method_name = :"#{key}_path"
|
7
|
-
|
8
|
-
metaclass = (class << self; self; end)
|
9
|
-
metaclass.instance_eval do
|
10
|
-
define_method method_name do |*attributes|
|
11
|
-
if attributes.any?
|
12
|
-
build_path(path, *attributes)
|
13
|
-
else
|
14
|
-
path
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
define_method method_name do |*attributes|
|
20
|
-
self.class.send(method_name, *attributes)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def build_path(path, attributes)
|
26
|
-
p = String.new(path)
|
27
|
-
p.gsub!(/=:([\w_]*)/) do
|
28
|
-
if $1.to_sym == :value and attributes[$1.to_sym].class == String
|
29
|
-
"=%22"+encode(attributes[$1.to_sym].to_s)+"%22";
|
30
|
-
else
|
31
|
-
"="+encode(attributes[$1.to_sym].to_s)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
p.gsub(/:([\w_]*)/) do
|
36
|
-
encode(attributes[$1.to_sym].to_s)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def encode(value)
|
41
|
-
CGI.escape(value).gsub("+", "%20")
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Neography
|
2
|
-
class Rest
|
3
|
-
class Properties
|
4
|
-
include Neography::Rest::Helpers
|
5
|
-
|
6
|
-
def initialize(connection)
|
7
|
-
@connection ||= connection
|
8
|
-
end
|
9
|
-
|
10
|
-
def set(id, properties)
|
11
|
-
properties.each do |property, value|
|
12
|
-
options = { :body => value.to_json, :headers => json_content_type }
|
13
|
-
@connection.put(single_path(:id => get_id(id), :property => property), options)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def reset(id, properties)
|
18
|
-
options = { :body => properties.to_json, :headers => json_content_type }
|
19
|
-
@connection.put(all_path(:id => get_id(id)), options)
|
20
|
-
end
|
21
|
-
|
22
|
-
def get(id, *properties)
|
23
|
-
if properties.none?
|
24
|
-
@connection.get(all_path(:id => get_id(id)))
|
25
|
-
else
|
26
|
-
get_each(id, *properties)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_each(id, *properties)
|
31
|
-
retrieved_properties = properties.flatten.inject({}) do |memo, property|
|
32
|
-
value = @connection.get(single_path(:id => get_id(id), :property => property))
|
33
|
-
memo[property] = value unless value.nil?
|
34
|
-
memo
|
35
|
-
end
|
36
|
-
return nil if retrieved_properties.empty?
|
37
|
-
retrieved_properties
|
38
|
-
end
|
39
|
-
|
40
|
-
def remove(id, *properties)
|
41
|
-
if properties.none?
|
42
|
-
@connection.delete(all_path(:id => get_id(id)))
|
43
|
-
else
|
44
|
-
remove_each(id, *properties)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def remove_each(id, *properties)
|
49
|
-
properties.flatten.each do |property|
|
50
|
-
@connection.delete(single_path(:id => get_id(id), :property => property))
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Neography
|
4
|
-
class Rest
|
5
|
-
|
6
|
-
class Dummy
|
7
|
-
extend Paths
|
8
|
-
|
9
|
-
add_path :one, "/node/:id"
|
10
|
-
add_path :two, "/node/:id/properties/:property"
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Dummy do
|
14
|
-
|
15
|
-
context "instance methods" do
|
16
|
-
|
17
|
-
it { should respond_to(:one_path) }
|
18
|
-
it { should respond_to(:two_path) }
|
19
|
-
|
20
|
-
it "replaces a key" do
|
21
|
-
subject.one_path(:id => 42).should == "/node/42"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "replaces multiple keys" do
|
25
|
-
subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "url encodes spaces" do
|
29
|
-
subject.one_path(:id => "with space").should == "/node/with%20space"
|
30
|
-
end
|
31
|
-
|
32
|
-
# URI.encode does not escape slashes (and rightly so), but should escape these keys
|
33
|
-
it "url encodes slashes" do
|
34
|
-
subject.one_path(:id => "with/slash").should == "/node/with%2Fslash"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
context "class methods" do
|
40
|
-
|
41
|
-
subject { Dummy }
|
42
|
-
|
43
|
-
it { should respond_to(:one_path) }
|
44
|
-
it { should respond_to(:two_path) }
|
45
|
-
|
46
|
-
it "replaces a key" do
|
47
|
-
subject.one_path(:id => 42).should == "/node/42"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "replaces multiple keys" do
|
51
|
-
subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "url encodes spaces" do
|
55
|
-
subject.one_path(:id => "with space").should == "/node/with%20space"
|
56
|
-
end
|
57
|
-
|
58
|
-
# URI.encode does not escape slashes (and rightly so), but should escape these keys
|
59
|
-
it "url encodes slashes" do
|
60
|
-
subject.one_path(:id => "with/slash").should == "/node/with%2Fslash"
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|