Class: Ashikawa::Core::EdgeCollection
- Inherits:
-
Collection
- Object
- Collection
- Ashikawa::Core::EdgeCollection
- Defined in:
- lib/ashikawa-core/edge_collection.rb
Overview
This is basically just a regular collection with some additional attributes and methods to ease working with collections in the graph module.
An edge collection as it is returned from a graph
Constant Summary collapse
- REMOVE_EDGES_AQL_STATEMENT =
The prepared AQL statement to remove edges
<<-AQL.gsub(/^[ \t]*/, '') FOR e IN @@edge_collection FILTER e._from == @from && e._to == @to REMOVE e._key IN @@edge_collection AQL
Constants inherited from Collection
Collection::CONTENT_CLASS, Collection::CONTENT_TYPES
Instance Attribute Summary collapse
-
#graph ⇒ Graph
readonly
The Graph instance this EdgeCollection was originally fetched from.
Attributes inherited from Collection
#content_type, #database, #id, #name, #status
Instance Method Summary collapse
-
#add(directions) ⇒ Edge
Create one or more edges between documents with certain attributes.
-
#build_content_class(data, additional_atttributes = {}) ⇒ Edge
private
Builds a new edge object and passes the current graph to it.
-
#initialize(database, raw_collection, graph) ⇒ EdgeCollection
constructor
Create a new EdgeCollection object.
-
#remove(from_to) ⇒ Object
Remove edges by example.
Methods inherited from Collection
#[], #add_index, #create_document, #create_edge, #delete, #fetch, #figure, #index, #indices, #key_options, #length, #load, #query, #replace, #truncate, #unload, #volatile?, #wait_for_sync=, #wait_for_sync?
Constructor Details
#initialize(database, raw_collection, graph) ⇒ EdgeCollection
You should not create instance manually but rather use Graph#add_edge_definition
Create a new EdgeCollection object
32 33 34 35 |
# File 'lib/ashikawa-core/edge_collection.rb', line 32 def initialize(database, raw_collection, graph) super(database, raw_collection) @graph = graph end |
Instance Attribute Details
#graph ⇒ Graph (readonly)
The Graph instance this EdgeCollection was originally fetched from
23 24 25 |
# File 'lib/ashikawa-core/edge_collection.rb', line 23 def graph @graph end |
Instance Method Details
#add(directions) ⇒ Edge
Create one or more edges between documents with certain attributes
46 47 48 49 50 |
# File 'lib/ashikawa-core/edge_collection.rb', line 46 def add(directions) from_vertex, to_vertex = directions.values_at(:from, :to) response = send_request_for_this_collection('', post: { _from: from_vertex.id, _to: to_vertex.id }) fetch(response['edge']['_key']) end |
#build_content_class(data, additional_atttributes = {}) ⇒ Edge
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a new edge object and passes the current graph to it
76 77 78 |
# File 'lib/ashikawa-core/edge_collection.rb', line 76 def build_content_class(data, additional_atttributes = {}) Edge.new(@database, data, additional_atttributes.merge(graph: graph)) end |
#remove(from_to) ⇒ Object
This will remove ALL edges between the given vertices. For more fine grained control delete the desired edges through Edge#remove.
Remove edges by example
60 61 62 63 64 65 66 67 68 |
# File 'lib/ashikawa-core/edge_collection.rb', line 60 def remove(from_to) bind_vars = { :@edge_collection => name, :from => from_to[:from].id, :to => from_to[:to].id } database.query.execute(REMOVE_EDGES_AQL_STATEMENT, bind_vars: bind_vars) end |