Class: Graphshaper::ArangoDbAdapter

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/graphshaper/adapters/arangodb_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(vertex_collection_name, edge_collection_name) ⇒ ArangoDbAdapter

Returns a new instance of ArangoDbAdapter.


10
11
12
13
14
15
16
17
# File 'lib/graphshaper/adapters/arangodb_adapter.rb', line 10

def initialize(vertex_collection_name, edge_collection_name)
  @vertex_collection_name = vertex_collection_name
  @edge_collection_name = edge_collection_name
  @vertex_matching = []
  @edge_matching = []

  [@vertex_collection_name, @edge_collection_name].each { |collection| drop_and_create_collection collection}
end

Instance Method Details

#add_edge(edge_id, from, to) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/graphshaper/adapters/arangodb_adapter.rb', line 26

def add_edge(edge_id, from, to)
  database_id_for_first_node = @vertex_matching[from]
  database_id_for_second_node = @vertex_matching[to]

  cmd = "/edge?collection=#{@edge_collection_name}&from=#{database_id_for_first_node}&to=#{database_id_for_second_node}"
  body = "{ \"id\" : \"#{edge_id}\" }"
  response = self.class.post(cmd, :body => body)
  @edge_matching[edge_id] = response.parsed_response["_id"]
end

#add_vertex(id) ⇒ Object


19
20
21
22
23
24
# File 'lib/graphshaper/adapters/arangodb_adapter.rb', line 19

def add_vertex(id)
  cmd = "/document?collection=#{@vertex_collection_name}"
  body = "{ \"id\" : \"#{id}\" }"
  response = self.class.post(cmd, :body => body)
  @vertex_matching[id] = response.parsed_response["_id"]
end

#closeObject


36
37
38
# File 'lib/graphshaper/adapters/arangodb_adapter.rb', line 36

def close

end