Module: Arango::Collection::EdgeAccess

Defined in:
lib/arango/edge_collection/edge_acces_2.rb

Overview

Arango EdgeCollection EdgeAccess

Instance Method Summary collapse

Instance Method Details

#destroy_edgeObject



133
134
135
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 133

def destroy_edge

end

#destroy_edges(edge: {}, wait_for_sync: nil, return_old: nil, ignore_revs: nil) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 136

def destroy_edges(edge: {}, wait_for_sync: nil, return_old: nil,
                      ignore_revs: nil)
  edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
  query = {
    waitForSync: wait_for_sync,
    returnOld:   return_old,
    ignoreRevs:  ignore_revs
  }
  @database.request("DELETE", "_api/edge/#{@id}", query: query, body: edge)
end

#edge(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object

Add an edge to the graph If no graph is defined, create a Document

@return: Vertex or Document



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 42

def edge(name: nil, body: {}, rev: nil, from: nil, to: nil)
  if @type == :document
    raise Arango::Error.new err: :is_a_document_collection, data: {type:  @type}
  end
  if @graph.nil?
    Arango::Document::Base.new(name: name, body: body, rev: rev, from: from, to: to, collection: self)
  else
    Arango::Edge::Base.new(name: name, body: body, rev: rev, from: from, to: to,
                     collection: self)
  end
end

#edges(type: "edge") ⇒ Object

“path”, “id”, “key”



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 55

def edges(type: "edge") # "path", "id", "key"
  @return_edge = false
  if type == "edge"
    @return_edge = true
    type = "key"
  end
  satisfy_category?(type, %w[path id key edge])
  body = { type: type, collection: @name }
  result = @database.request("PUT", "_api/simple/all-keys", body: body)

  @has_more_simple = result[:hasMore]
  @id_simple = result[:id]
  return result if return_directly?(result)
  return result[:result] unless @return_edge
  if @return_edge
    result[:result].map{|key| Arango::Document::Base.new(name: key, collection: self)}
  end
end

#graph=(graph) ⇒ Object Also known as: assign_graph

Set the graph of the EdgeAccess instance



9
10
11
12
13
14
15
16
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 9

def graph=(graph)
  satisfy_module_or_nil?(graph, Arango::Graph::Mixin)
  if !graph.nil? && graph.database.name != @database.name
    raise Arango::Error.new err: :database_graph_no_same_as_collection_database,
                            data: { graph_database_name: graph.database.name, collection_database_name:  @database.name}
  end
  @graph = graph
end

#replace_edgeObject



74
75
76
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 74

def replace_edge

end

#replace_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil, return_old: nil, return_new: nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 78

def replace_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil,
                      return_old: nil, return_new: nil)
  edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
  query = {
    waitForSync: wait_for_sync,
    returnNew:   return_new,
    returnOld:   return_old,
    ignoreRevs:  ignore_revs
  }
  result = @database.request("PUT", "_api/edge/#{@name}", body: edge,
                             query: query)
  return results if return_directly?(result)
  results.map.with_index do |result, index|
    body2 = result.clone
    if return_new == true
      body2.delete(:new)
      body2 = body2.merge(result[:new])
    end
    real_body = edge[index]
    real_body = real_body.merge(body2)
    Arango::Document::Base.new(name: result[:_key], collection: self, body: real_body)
  end
end

#update_edgeObject



102
103
104
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 102

def update_edge

end

#update_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil, return_old: nil, return_new: nil, keep_null: nil, merge_objects: nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 106

def update_edges(edge: {}, wait_for_sync: nil, ignore_revs: nil,
                     return_old: nil, return_new: nil, keep_null: nil, merge_objects: nil)
  edge.each{|x| x = x.body if x.is_a?(Arango::Document)}
  query = {
    waitForSync: wait_for_sync,
    returnNew:   return_new,
    returnOld:   return_old,
    ignoreRevs:  ignore_revs,
    keepNull:    keep_null,
    mergeObject: merge_objects
  }
  result = @database.request("PATCH", "_api/edge/#{@name}", body: edge,
                             query: query, keep_null: keep_null)
  return results if return_directly?(result)
  results.map.with_index do |result, index|
    body2 = result.clone
    if return_new
      body2.delete(:new)
      body2 = body2.merge(result[:new])
    end
    real_body = edge[index]
    real_body = real_body.merge(body2)
    Arango::Document::Base.new(name: result[:_key], collection: self,
                         body: real_body)
  end
end

#vertex(name: nil, body: {}, rev: nil, from: nil, to: nil) ⇒ Object

Add a vertex to the graph If no graph is defined, create a Document

@return: Vertex or Document



25
26
27
28
29
30
31
32
33
34
# File 'lib/arango/edge_collection/edge_acces_2.rb', line 25

def vertex(name: nil, body: {}, rev: nil, from: nil, to: nil)
  if @type == :edge
    raise Arango::Error.new err: :is_a_edge_collection, data: {type:  @type}
  end
  if @graph.nil?
    Arango::Document::Base.new(name: name, body: body, rev: rev, collection: self, from: from, to: to)
  else
    Arango::Vertex.new(name: name, body: body, rev: rev, collection: self, from: from, to: to)
  end
end