Module: Pacer::EdgeMixin
- Included in:
- DexEdge, EdgeWrapper, Neo4jEdge, TinkerEdge
- Defined in:
- lib/pacer/graph/edge_mixin.rb
Overview
This module is mixed into the raw Blueprints Edge class from any graph implementation.
Adds more convenient/rubyish methods and adds support for extensions to some methods where needed.
Instance Method Summary (collapse)
-
- (Pacer::EdgeWrapper) add_extensions(exts)
Add extensions to this edge.
-
- (Pacer::EdgeMixin) clone_into(target_graph, opts = {}) {|e| ... }
Clones this edge into the target graph.
-
- (Pacer::EdgeMixin) copy_into(target_graph) {|e| ... }
Copies this edge into the target graph with the next available edge id.
-
- (Object) delete!
Deletes the edge from its graph.
-
- (String) display_name
Returns the display name of the edge.
-
- (Pacer::VertexMixin) in_vertex(extensions = nil)
The incoming vertex for this edge.
-
- (String) inspect
Returns a human-readable representation of the edge using the standard ruby console representation of an instantiated object.
-
- (Pacer::VertexMixin) out_vertex(extensions = nil)
The outgoing vertex for this edge.
Instance Method Details
- (Pacer::EdgeWrapper) add_extensions(exts)
Add extensions to this edge.
If any extension has a Edge module within it, this edge will be extended with the extension's Edge module.
18 19 20 21 22 23 24 |
# File 'lib/pacer/graph/edge_mixin.rb', line 18 def add_extensions(exts) if exts.any? EdgeWrapper.wrap(self, exts) else self end end |
- (Pacer::EdgeMixin) clone_into(target_graph, opts = {}) {|e| ... }
Clones this edge into the target graph.
This differs from the #copy_into in that it tries to set the new element_id the same as the original element_id.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pacer/graph/edge_mixin.rb', line 85 def clone_into(target_graph, opts = {}) e_idx = target_graph.index_name("tmp:e:#{graph.to_s}", :edge, :create => true) e = target_graph.edge(element_id) || e_idx.get('id', element_id).first unless e v_idx = target_graph.index_name("tmp:v:#{graph.to_s}", :vertex, :create => true) iv = target_graph.vertex(in_vertex.element_id) || v_idx.get('id', in_vertex.element_id).first ov = target_graph.vertex(out_vertex.element_id) || v_idx.get('id', out_vertex.element_id).first if opts[:create_vertices] iv ||= in_vertex.clone_into target_graph ov ||= out_vertex.clone_into target_graph end raise 'vertices not found' if not iv or not ov e = target_graph.create_edge(element_id, iv, ov, label, properties) e_idx.put('id', element_id, e) yield e if block_given? end e end |
- (Pacer::EdgeMixin) copy_into(target_graph) {|e| ... }
Copies this edge into the target graph with the next available edge id.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/pacer/graph/edge_mixin.rb', line 112 def copy_into(target_graph) v_idx = target_graph.index_name("tmp:v:#{graph.to_s}", :vertex, :create => true) iv = v_idx.get('id', in_vertex.element_id).first || target_graph.vertex(in_vertex.element_id) ov = v_idx.get('id', out_vertex.element_id).first || target_graph.vertex(out_vertex.element_id) raise 'vertices not found' if not iv or not ov e = target_graph.create_edge nil, iv, ov, label, properties yield e if block_given? e end |
- (Object) delete!
Deletes the edge from its graph.
68 69 70 |
# File 'lib/pacer/graph/edge_mixin.rb', line 68 def delete! graph.remove_edge element end |
- (String) display_name
Returns the display name of the edge.
59 60 61 62 63 64 65 |
# File 'lib/pacer/graph/edge_mixin.rb', line 59 def display_name if graph and graph.edge_name graph.edge_name.call self else "#{ out_vertex.element_id }-#{ get_label }-#{ in_vertex.element_id }" end end |
- (Pacer::VertexMixin) in_vertex(extensions = nil)
The incoming vertex for this edge.
28 29 30 31 32 33 34 35 36 |
# File 'lib/pacer/graph/edge_mixin.rb', line 28 def in_vertex(extensions = nil) v = inVertex v.graph = graph if extensions v.add_extensions extensions else v end end |
- (String) inspect
Returns a human-readable representation of the edge using the standard ruby console representation of an instantiated object.
53 54 55 |
# File 'lib/pacer/graph/edge_mixin.rb', line 53 def inspect "#<E[#{element_id}]:#{display_name}>" end |
- (Pacer::VertexMixin) out_vertex(extensions = nil)
The outgoing vertex for this edge.
40 41 42 43 44 45 46 47 48 |
# File 'lib/pacer/graph/edge_mixin.rb', line 40 def out_vertex(extensions = nil) v = outVertex v.graph = graph if extensions v.add_extensions extensions else v end end |