Class: Rebat::Client
- Inherits:
-
Object
- Object
- Rebat::Client
- Defined in:
- lib/rebat/client.rb
Instance Attribute Summary collapse
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #add(from_entity_id, from_entity_type, to_entity_id, to_entity_type, weight, relation_key) ⇒ Object
- #close ⇒ Object
- #delete(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key) ⇒ Object
- #exclude(*args) ⇒ Object
-
#initialize(host, port, relations = {}) ⇒ Client
constructor
A new instance of Client.
- #intersect(*args) ⇒ Object
- #sendQuery(&block) ⇒ Object
- #truncate ⇒ Object
- #union(*args) ⇒ Object
- #updateWeight(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key, new_weight) ⇒ Object
- #where(*args) ⇒ Object
Constructor Details
#initialize(host, port, relations = {}) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 10 11 |
# File 'lib/rebat/client.rb', line 4 def initialize(host, port, relations = {}) @transport = Thrift::BufferedTransport.new(Thrift::Socket.new(host, port)) @protocol = Thrift::BinaryProtocol.new(@transport) @client = Rebat::Thrift::RebatDB::Client.new(@protocol) @relations = relations @transport.open end |
Instance Attribute Details
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
2 3 4 |
# File 'lib/rebat/client.rb', line 2 def relations @relations end |
Instance Method Details
#add(from_entity_id, from_entity_type, to_entity_id, to_entity_type, weight, relation_key) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rebat/client.rb', line 26 def add(from_entity_id, from_entity_type, to_entity_id, to_entity_type, weight, relation_key) edge = Rebat::Thrift::Edge.new edge.fromEntityId = from_entity_id.to_s edge.fromEntityType = from_entity_type edge.toEntityId = to_entity_id.to_s edge.toEntityType = to_entity_type edge.weight = weight edge.relationId = relations[relation_key] self.sendQuery do |client| client.addQuery(edge) end end |
#close ⇒ Object
22 23 24 |
# File 'lib/rebat/client.rb', line 22 def close @transport.close end |
#delete(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rebat/client.rb', line 55 def delete(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key) edge = Rebat::Thrift::Edge.new edge.fromEntityId = from_entity_id.to_s edge.fromEntityType = from_entity_type edge.toEntityId = to_entity_id.to_s edge.toEntityType = to_entity_type edge.relationId = relations[relation_key] self.sendQuery do |client| client.deleteQuery(edge) end end |
#exclude(*args) ⇒ Object
81 82 83 |
# File 'lib/rebat/client.rb', line 81 def exclude(*args) Rebat::Selector.new(self).exclude *args end |
#intersect(*args) ⇒ Object
77 78 79 |
# File 'lib/rebat/client.rb', line 77 def intersect(*args) Rebat::Selector.new(self).intersect *args end |
#sendQuery(&block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/rebat/client.rb', line 13 def sendQuery(&block) begin @transport.open unless @transport.open? yield @client rescue Thrift::Exception => tx print 'Thrift::Exception: ', tx., "\n" end end |
#truncate ⇒ Object
85 86 87 88 89 |
# File 'lib/rebat/client.rb', line 85 def truncate self.sendQuery do |client| client.truncate end end |
#union(*args) ⇒ Object
73 74 75 |
# File 'lib/rebat/client.rb', line 73 def union(*args) Rebat::Selector.new(self).union *args end |
#updateWeight(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key, new_weight) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rebat/client.rb', line 41 def updateWeight(from_entity_id, from_entity_type, to_entity_id, to_entity_type, relation_key, new_weight) edge = Rebat::Thrift::Edge.new edge.fromEntityId = from_entity_id.to_s edge.fromEntityType = from_entity_type edge.toEntityId = to_entity_id.to_s edge.toEntityType = to_entity_type edge.relationId = relations[relation_key] self.sendQuery do |client| client.updateWeightQuery(edge, new_weight) end end |