class Ashikawa::Core::EdgeCollection
An edge collection as it is returned from a graph
@note This is basically just a regular collection with some additional attributes and methods to ease
working with collections in the graph module.
Constants
- REMOVE_EDGES_AQL_STATEMENT
The prepared AQL statement to remove edges
Attributes
The Graph
instance this EdgeCollection
was originally fetched from
@return [Graph] The Graph
instance the collection was fetched from @api public
Public Class Methods
Create a new EdgeCollection
object
@param [Database] database The database the connection belongs to @param [Hash] raw_collection The raw collection returned from the server @param [Graph] graph The graph from which this collection was fetched @note You should not create instance manually but rather use Graph#add_edge_definition
@api public
Ashikawa::Core::Collection::new
# File lib/ashikawa-core/edge_collection.rb, line 31 def initialize(database, raw_collection, graph) super(database, raw_collection) @graph = graph end
Public Instance Methods
Create one or more edges between documents with certain attributes
@param [Document] from The outbound vertex @param [Document] to The inbound vertex @param [Hash] attributes Additional attributes to add to all created edges @return [Edge] The created Edge
@api public @example Create an edge between two vertices
edges = edge_collection.add(from: vertex_a, to: vertex_b)
# File lib/ashikawa-core/edge_collection.rb, line 45 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
Builds a new edge object and passes the current graph to it
@param [Hash] data The raw data to be used to instatiate the class @param [Hash] additional_atttributes Initial attributes to be passed to the Edge
@return [Edge] The instatiated edge @api private
# File lib/ashikawa-core/edge_collection.rb, line 75 def build_content_class(data, additional_atttributes = {}) Edge.new(@database, data, additional_atttributes.merge(graph: graph)) end
Remove edges by example
@note This will remove ALL edges between the given vertices. For more fine grained control delete
the desired edges through Edge#remove.
@param [Hash] from_to Specifies the edge by its vertices to be removed @option from_to [Document] from The from part of the edge @option from_to [Document] to The to part of the edge @api public
# File lib/ashikawa-core/edge_collection.rb, line 59 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
Private Instance Methods
Send a request to the server through the Graph
module
@param [String] path The requested path @param [Hash] method The desired HTTP Verb (defaults to GET) and its parameters @return [Hash] Response from the server @api private
# File lib/ashikawa-core/edge_collection.rb, line 87 def send_request_for_this_collection(path, method = {}) send_request("gharial/#{graph.name}/edge/#@name/#{path}", method) end