Module: Guacamole::EdgeCollection::ClassMethods

Defined in:
lib/guacamole/edge_collection.rb

Instance Method Summary collapse

Instance Method Details

#add_edge_definition_to_graphObject



41
42
43
44
45
46
47
48
49
# File 'lib/guacamole/edge_collection.rb', line 41

def add_edge_definition_to_graph
  graph.add_edge_definition(collection_name,
                            from: [edge_class.from],
                            to: [edge_class.to])
rescue Ashikawa::Core::ResourceNotFound
  # FIXME: We just assume this 404 is raised because the edge definition is already created.
  #        But the source of the error could be something else too. Had to be changed as soon
  #        https://github.com/triAGENS/ashikawa-core/issues/136 is done.
end

#connectionObject



33
34
35
# File 'lib/guacamole/edge_collection.rb', line 33

def connection
  @connection ||= graph.edge_collection(collection_name)
end

#edge_classObject



37
38
39
# File 'lib/guacamole/edge_collection.rb', line 37

def edge_class
  @edge_class ||= model_class
end

#mapper_for_start(model) ⇒ Object



78
79
80
# File 'lib/guacamole/edge_collection.rb', line 78

def mapper_for_start(model)
  vertex_mapper.find { |mapper| mapper.responsible_for?(model) }
end

#mapper_for_target(model) ⇒ Object



74
75
76
# File 'lib/guacamole/edge_collection.rb', line 74

def mapper_for_target(model)
  vertex_mapper.find { |mapper| !mapper.responsible_for?(model) }
end

#neighbors(model, direction = :inbound) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/guacamole/edge_collection.rb', line 51

def neighbors(model, direction = :inbound)
  aql_string = <<-AQL
  FOR n IN GRAPH_NEIGHBORS(@graph,
                  { _key: @model_key },
                  { direction: @direction, edgeCollectionRestriction: @edge_collection })
    RETURN n.vertex
  AQL

  bind_parameters = {
    graph: Guacamole.configuration.graph.name,
    model_key: model.key,
    edge_collection: collection_name,
    direction: direction
  }

  options = { return_as: nil, for_in: nil }

  query                 = AqlQuery.new(self, mapper_for_target(model), options)
  query.aql_fragment    = aql_string
  query.bind_parameters = bind_parameters
  query
end

#vertex_mapperObject



82
83
84
# File 'lib/guacamole/edge_collection.rb', line 82

def vertex_mapper
  [edge_class.from_collection, edge_class.to_collection].map(&:mapper)
end