Class: Rebat::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rebat/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#relationsObject (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

#closeObject



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.message, "\n"
  end
end

#truncateObject



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

#where(*args) ⇒ Object



69
70
71
# File 'lib/rebat/client.rb', line 69

def where(*args)
  Rebat::Selector.new(self).where *args
end