rebat 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rebat/client.rb +13 -7
- data/lib/rebat/selector.rb +8 -8
- data/lib/rebat/version.rb +1 -1
- metadata +3 -3
data/lib/rebat/client.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
class Rebat::Client
|
2
|
-
|
2
|
+
attr_reader :relations
|
3
|
+
|
4
|
+
def initialize(host, port, relations = {})
|
3
5
|
@transport = Thrift::BufferedTransport.new(Thrift::Socket.new(host, port))
|
4
6
|
@protocol = Thrift::BinaryProtocol.new(@transport)
|
5
7
|
@client = Rebat::Thrift::RebatDB::Client.new(@protocol)
|
8
|
+
@relations = relations
|
6
9
|
|
7
10
|
@transport.open
|
8
11
|
end
|
@@ -20,7 +23,7 @@ class Rebat::Client
|
|
20
23
|
@transport.close
|
21
24
|
end
|
22
25
|
|
23
|
-
def add(from_entity_id, from_entity_type, to_entity_id, to_entity_type, weight,
|
26
|
+
def add(from_entity_id, from_entity_type, to_entity_id, to_entity_type, weight, relation_key)
|
24
27
|
edge = Rebat::Thrift::Edge.new
|
25
28
|
|
26
29
|
edge.fromEntityId = from_entity_id
|
@@ -28,35 +31,35 @@ class Rebat::Client
|
|
28
31
|
edge.toEntityId = to_entity_id
|
29
32
|
edge.toEntityType = to_entity_type
|
30
33
|
edge.weight = weight
|
31
|
-
edge.relationId =
|
34
|
+
edge.relationId = relations[relation_key]
|
32
35
|
|
33
36
|
self.send do |client|
|
34
37
|
client.addQuery(edge)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
|
-
def updateWeight(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
41
|
+
def updateWeight(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key, new_weight)
|
39
42
|
edge = Rebat::Thrift::Edge.new
|
40
43
|
|
41
44
|
edge.fromEntityId = from_entity_id
|
42
45
|
edge.fromEntityType = from_entity_type
|
43
46
|
edge.toEntityId = to_entity_id
|
44
47
|
edge.toEntityType = to_entity_type
|
45
|
-
edge.relationId =
|
48
|
+
edge.relationId = relations[relation_key]
|
46
49
|
|
47
50
|
self.send do |client|
|
48
51
|
client.updateWeightQuery(edge, new_weight)
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
|
-
def delete(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
55
|
+
def delete(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
|
53
56
|
edge = Rebat::Thrift::Edge.new
|
54
57
|
|
55
58
|
edge.fromEntityId = from_entity_id
|
56
59
|
edge.fromEntityType = from_entity_type
|
57
60
|
edge.toEntityId = to_entity_id
|
58
61
|
edge.toEntityType = to_entity_type
|
59
|
-
edge.relationId =
|
62
|
+
edge.relationId = relations[relation_key]
|
60
63
|
|
61
64
|
self.send do |client|
|
62
65
|
client.deleteQuery(edge)
|
@@ -78,4 +81,7 @@ class Rebat::Client
|
|
78
81
|
def exclude(*args)
|
79
82
|
Rebat::Selector.new(self).exclude *args
|
80
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
attr_reader :transport, :protocol, :client
|
81
87
|
end
|
data/lib/rebat/selector.rb
CHANGED
@@ -6,23 +6,23 @@ class Rebat::Selector
|
|
6
6
|
@query_list = []
|
7
7
|
end
|
8
8
|
|
9
|
-
def where(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
10
|
-
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
9
|
+
def where(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
|
10
|
+
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::WHERE)
|
11
11
|
return self
|
12
12
|
end
|
13
13
|
|
14
|
-
def union(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
15
|
-
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
14
|
+
def union(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
|
15
|
+
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::UNION)
|
16
16
|
return self
|
17
17
|
end
|
18
18
|
|
19
|
-
def intersect(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
20
|
-
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
19
|
+
def intersect(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
|
20
|
+
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::INTERSECT)
|
21
21
|
return self
|
22
22
|
end
|
23
23
|
|
24
|
-
def exclude(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
25
|
-
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type,
|
24
|
+
def exclude(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key)
|
25
|
+
@query_list << create_query(from_entity_id, from_entity_type, to_entity_id, to_entity_type, @client.relations[relation_key], Rebat::Thrift::QueryType::EXCLUDE)
|
26
26
|
return self
|
27
27
|
end
|
28
28
|
|
data/lib/rebat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rebat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-09-16 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thrift
|
17
|
-
requirement: &
|
17
|
+
requirement: &70255955289740 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: 0.8.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70255955289740
|
26
26
|
description: ! 'Rebat DB driver for ruby '
|
27
27
|
email:
|
28
28
|
- omar.mekky@mashsolvents.com
|