Class: Arango::Traversal
- Inherits:
-
Object
- Object
- Arango::Traversal
- Includes:
- Database_Return, Helper_Error, Helper_Return
- Defined in:
- lib/Traversal.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#edgeCollection ⇒ Object
Returns the value of attribute edgeCollection.
-
#expander ⇒ Object
DEFINE ===.
-
#filter ⇒ Object
DEFINE ===.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#init ⇒ Object
DEFINE ===.
-
#itemOrder ⇒ Object
Returns the value of attribute itemOrder.
-
#maxDepth ⇒ Object
(also: #max)
DEFINE ===.
-
#maxiterations ⇒ Object
DEFINE ===.
-
#minDepth ⇒ Object
(also: #min)
DEFINE ===.
-
#order ⇒ Object
Returns the value of attribute order.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#sort ⇒ Object
DEFINE ===.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
-
#uniqueness ⇒ Object
DEFINE ===.
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
-
#visitor ⇒ Object
DEFINE ===.
Instance Method Summary collapse
- #any ⇒ Object
-
#execute ⇒ Object
EXECUTE ===.
- #in ⇒ Object
-
#initialize(body: {}, edgeCollection: nil, sort: nil, direction: nil, minDepth: nil, vertex:, visitor: nil, itemOrder: nil, strategy: nil, filter: nil, init: nil, maxIterations: nil, maxDepth: nil, uniqueness: nil, order: nil, expander: nil) ⇒ Traversal
constructor
A new instance of Traversal.
- #out ⇒ Object
- #startVertex=(vertex) ⇒ Object (also: #vertex=, #return_vertex)
-
#to_h ⇒ Object
TO HASH ===.
Methods included from Database_Return
Methods included from Helper_Return
#return_delete, #return_directly?, #return_element
Methods included from Helper_Error
#satisfy_category?, #satisfy_class?, #warning_deprecated
Constructor Details
#initialize(body: {}, edgeCollection: nil, sort: nil, direction: nil, minDepth: nil, vertex:, visitor: nil, itemOrder: nil, strategy: nil, filter: nil, init: nil, maxIterations: nil, maxDepth: nil, uniqueness: nil, order: nil, expander: nil) ⇒ Traversal
Returns a new instance of Traversal.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/Traversal.rb', line 9 def initialize(body: {}, edgeCollection: nil, sort: nil, direction: nil, minDepth: nil, vertex:, visitor: nil, itemOrder: nil, strategy: nil, filter: nil, init: nil, maxIterations: nil, maxDepth: nil, uniqueness: nil, order: nil, expander: nil) satisfy_category?(direction, ["outbound", "inbound", "any", nil]) satisfy_category?(itemOrder, ["forward", "backward", nil]) satisfy_category?(strategy, ["depthfirst", "breadthfirst", nil]) satisfy_category?(order, ["preorder", "postorder", "preorder-expander", nil]) body[:sort] ||= sort body[:direction] ||= direction body[:maxDepth] ||= maxDepth body[:minDepth] ||= minDepth body[:startVertex] ||= vertex body[:visitor] ||= visitor body[:itemOrder] ||= itemOrder body[:strategy] ||= strategy body[:filter] ||= filter body[:init] ||= init body[:maxiterations] ||= maxIterations body[:uniqueness] ||= uniqueness body[:order] ||= order body[:expander] ||= body[:edgeCollection] ||= edgeCollection assign_body(body) @vertices = nil @paths = nil end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def body @body end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def collection @collection end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def database @database end |
#direction ⇒ Object
Returns the value of attribute direction.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def direction @direction end |
#edgeCollection ⇒ Object
Returns the value of attribute edgeCollection.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def edgeCollection @edgeCollection end |
#expander ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def @expander end |
#filter ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def filter @filter end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def graph @graph end |
#init ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def init @init end |
#itemOrder ⇒ Object
Returns the value of attribute itemOrder.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def itemOrder @itemOrder end |
#maxDepth ⇒ Object Also known as: max
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def maxDepth @maxDepth end |
#maxiterations ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def maxiterations @maxiterations end |
#minDepth ⇒ Object Also known as: min
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def minDepth @minDepth end |
#order ⇒ Object
Returns the value of attribute order.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def order @order end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def paths @paths end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def server @server end |
#sort ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def sort @sort end |
#strategy ⇒ Object
Returns the value of attribute strategy.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def strategy @strategy end |
#uniqueness ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def uniqueness @uniqueness end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
41 42 43 |
# File 'lib/Traversal.rb', line 41 def vertices @vertices end |
#visitor ⇒ Object
DEFINE ===
40 41 42 |
# File 'lib/Traversal.rb', line 40 def visitor @visitor end |
Instance Method Details
#any ⇒ Object
142 143 144 |
# File 'lib/Traversal.rb', line 142 def any @direction = "any" end |
#execute ⇒ Object
EXECUTE ===
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/Traversal.rb', line 180 def execute body = { "sort": @sort, "direction": @direction, "maxDepth": @maxDepth, "minDepth": @minDepth, "startVertex": @vertex&.id, "visitor": @visitor, "itemOrder": @itemOrder, "strategy": @strategy, "filter": @filter, "init": @init, "maxiterations": @maxiterations, "uniqueness": @uniqueness, "order": @order, "graphName": @graph&.name, "expander": @expander, "edgeCollection": @edgeCollection&.name } result = @database.request("POST", "_api/traversal", body: body) return result if @server.async != false @vertices = result[:result][:visited][:vertices].map do |x| collection = Arango::Collection.new(name: x[:_id].split("/")[0], database: @database) Arango::Document.new(name: x[:_key], collection: collection, body: x) end @paths = result[:result][:visited][:paths].map do |x| { "edges": x[:edges].map do |e| collection_edge = Arango::Collection.new(name: e[:_id].split("/")[0], database: @database, type: :edge) Arango::Document.new(name: e[:_key], collection: collection_edge, body: e, from: e[:_from], to: e[:_to]) end, "vertices": x[:vertices].map do |v| collection_vertex = Arango::Collection.new(name: v[:_id].split("/")[0], database: @database) Arango::Document.new(name: v[:_key], collection: collection_vertex, body: v) end } end return return_directly?(result) ? result : self end |
#in ⇒ Object
134 135 136 |
# File 'lib/Traversal.rb', line 134 def in @direction = "inbound" end |
#out ⇒ Object
138 139 140 |
# File 'lib/Traversal.rb', line 138 def out @direction = "outbound" end |
#startVertex=(vertex) ⇒ Object Also known as: vertex=, return_vertex
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/Traversal.rb', line 85 def startVertex=(vertex) case vertex when Arango::Edge when Arango::Document, Arango::Vertex @vertex = vertex @collection = @vertex.collection @database = @collection.database @graph = @collection.graph @server = @database.server return when String if @database.nil? raise Arango::Error.new err: :database_undefined_for_traversal elsif vertex.include? "/" val = vertex.split("/") @collection = Arango::Collection.new(database: @database, name: val[0]) @vertex = Arango::Document.new(collection: @collection, name: val[1]) return end end raise Arango::Error.new err: :wrong_start_vertex_type end |
#to_h ⇒ Object
TO HASH ===
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/Traversal.rb', line 148 def to_h { "sort": @sort, "direction": @direction, "maxDepth": @maxDepth, "minDepth": @minDepth, "visitor": @visitor, "itemOrder": @itemOrder, "strategy": @strategy, "filter": @filter, "init": @init, "maxiterations": @maxiterations, "uniqueness": @uniqueness, "order": @order, "expander": @expander, "vertices": @vertices&.map{|x| x.id}, "paths": @paths&.map do |x| { "edges": x[:edges]&.map{|e| e.id}, "vertices": x[:vertices]&.map{|v| v.id} } end, "idCache": @idCache, "startVertex": @vertex&.id, "graph": @graph&.name, "edgeCollection": @edgeCollection&.name, "database": @database.name }.delete_if{|k,v| v.nil?} end |