Class: Arcade::Edge
Direct Known Subclasses
Class Method Summary collapse
-
.create(from:, to:, **attr) ⇒ Object
Add Contrains to the edge CREATE INDEX Watched_out_in ON <edge type« (‘@out`, `@in`) UNIQUE.
-
.delete(from:, to:) ⇒ Object
class-method: Delete Edge between two vertices.
Instance Method Summary collapse
- #accepted_methods ⇒ Object
-
#delete ⇒ Object
instance method: Delete specified edge.
-
#inV ⇒ Object
gets the adjacent Vertex.
- #outV ⇒ Object
- #to_human ⇒ Object
- #vertices(in_or_out = nil) ⇒ Object (also: #bothV)
Methods inherited from Base
#==, all, begin_transaction, commit, count, create_type, database_name, descendants, drop_type, find, first, #html_attributes, #in_and_out_attributes, insert, #insert_document, #inspect, #invariant_attributes, last, #method_missing, not_permitted, properties, query, #query, #refresh, #rid?, rollback, timestamps, #to_html, #to_json, #to_or, update, #update, update!, #update_embedded, #update_list, #update_map, upsert, where
Methods included from Support::Sql
#compose_where, #generate_sql_list
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Arcade::Base
Class Method Details
.create(from:, to:, **attr) ⇒ Object
Add Contrains to the edge CREATE INDEX Watched_out_in ON <edge type« (‘@out`, `@in`) UNIQUE
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/model/edge.rb', line 14 def self.create from:, to:, **attr db.create_edge database_name, from: from, to: to, **attr rescue Arcade::QueryError => e if e. =~ /Duplicated key\s+.+\sfound on index/ if e.args.keys.first == :exceptionArgs # return the previously assigned edge e.args[:exceptionArgs].split('|').last.load_rid else raise end else raise end end |
.delete(from:, to:) ⇒ Object
class-method: Delete Edge between two vertices
returns the count of deleted edges
todo: add conditions
36 37 38 39 40 41 42 43 |
# File 'lib/model/edge.rb', line 36 def self.delete from:, to: return 0 if from.nil? || to.nil? raise "parameter ( from: ) must be a String or a Vertex" unless from.is_a?(String) || from.is_a?( Arcade::Vertex) raise "parameter ( to: ) must be a String or a Vertex" unless to.is_a?(String) || to.is_a?( Arcade::Vertex) raise "parameters (from: + to:) must respond to `.rid`" unless from.respond_to?( :rid) && to.respond_to?(:rid) db.execute{ "delete edge from #{from.rid} to #{to.rid} " } &.select_result &.first end |
Instance Method Details
#accepted_methods ⇒ Object
7 8 9 |
# File 'lib/model/edge.rb', line 7 def accepted_methods super + [ :vertices, :in, :out, :inV, :outV ] end |
#delete ⇒ Object
instance method: Delete specified edge
47 48 49 |
# File 'lib/model/edge.rb', line 47 def delete db.execute{ "delete edge #{ rid }" }.select_result end |
#inV ⇒ Object
gets the adjacent Vertex
51 52 53 |
# File 'lib/model/edge.rb', line 51 def inV query( projection: "inV()").query.select_result end |
#outV ⇒ Object
54 55 56 |
# File 'lib/model/edge.rb', line 54 def outV query( projection: "outV()").query.select_result end |
#to_human ⇒ Object
71 72 73 |
# File 'lib/model/edge.rb', line 71 def to_human "<#{self.class.to_s.snake_case}[#{rid}] :.: #{ out }->#{invariant_attributes}->#{ attributes[:in] }>" end |
#vertices(in_or_out = nil) ⇒ Object Also known as: bothV
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/model/edge.rb', line 57 def vertices in_or_out = nil case in_or_out when :in inV when :out outV else [inV, outV] end end |