Class: Arango::Edge

Inherits:
Document show all
Defined in:
lib/Edge.rb

Instance Attribute Summary collapse

Attributes inherited from Document

#body, #cache_name

Instance Method Summary collapse

Methods inherited from Document

#any, #edges, #from, #from=, #head, #id, #id=, #in, #name, #name=, new, #out, #rev, #rev=, #to, #to=, #to_h, #traversal

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(name: nil, collection:, body: {}, rev: nil, from: nil, to: nil) ⇒ Edge

Returns a new instance of Edge.



5
6
7
8
9
10
11
12
13
14
# File 'lib/Edge.rb', line 5

def initialize(name: nil, collection:, body: {}, rev: nil, from: nil,
  to: nil)
  assign_collection(collection)
  body[:_key]  ||= name
  body[:_rev]  ||= rev
  body[:_from] ||= from
  body[:_to]   ||= to
  body[:_id]   ||= "#{@collection.name}/#{name}" unless name.nil?
  assign_attributes(body)
end

Instance Attribute Details

#collectionObject

DEFINE ===



18
19
20
# File 'lib/Edge.rb', line 18

def collection
  @collection
end

#databaseObject (readonly)

DEFINE ===



18
19
20
# File 'lib/Edge.rb', line 18

def database
  @database
end

#graphObject (readonly)

DEFINE ===



18
19
20
# File 'lib/Edge.rb', line 18

def graph
  @graph
end

#serverObject (readonly)

DEFINE ===



18
19
20
# File 'lib/Edge.rb', line 18

def server
  @server
end

Instance Method Details

#create(body: {}, waitForSync: nil) ⇒ Object

POST ==



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/Edge.rb', line 45

def create(body: {}, waitForSync: nil)
  body = @body.merge(body)
  query = {
    "waitForSync": waitForSync,
    "_from":      @body[:_from],
    "_to":        @body[:_to]
  }
  result = @graph.request("POST", "edge/#{@collection.name}", body: body,
    query: query, key: :edge)
  return result if @server.async != false
  body2 = result.clone
  body = body.merge(body2)
  assign_attributes(body)
  return return_directly?(result) ? result : self
end

#destroy(waitForSync: nil, if_match: false) ⇒ Object

DELETE ===



95
96
97
98
99
100
101
102
# File 'lib/Edge.rb', line 95

def destroy(waitForSync: nil, if_match: false)
  query = {"waitForSync": waitForSync}
  headers = {}
  headers[:"If-Match"] = @body[:_rev] if if_match
  result = @graph.request("DELETE", "edge/#{@collection.name}/#{@body[:_key]}",
    query: query, headers: headers)
  return_delete(result)
end

#replace(body: {}, waitForSync: nil, keepNull: nil, if_match: false) ⇒ Object

PUT ==



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Edge.rb', line 63

def replace(body: {}, waitForSync: nil, keepNull: nil, if_match: false)
  query = {
    "waitForSync": waitForSync,
    "keepNull":    keepNull
  }
  headers = {}
  headers[:"If-Match"] = @body[:_rev] if if_match
  result = @graph.request("PUT", "edge/#{@collection.name}/#{@body[:_key]}",
    body: body, query: query, headers: headers, key: :edge)
  return result if @server.async != false
  body2 = result.clone
  body = body.merge(body2)
  assign_attributes(body)
  return return_directly?(result) ? result : self
end

#retrieve(if_match: false) ⇒ Object

GET ==



35
36
37
38
39
40
41
# File 'lib/Edge.rb', line 35

def retrieve(if_match: false)
  headers = {}
  headers[:"If-Match"] = @body[:_rev] if if_match
  result = @graph.request("GET", "edge/#{@collection.name}/#{@body[:_key]}",
    headers: headers, key: :edge)
  return_element(result)
end

#update(body: {}, waitForSync: nil, if_match: false) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/Edge.rb', line 79

def update(body: {}, waitForSync: nil, if_match: false)
  query = {"waitForSync": waitForSync}
  headers = {}
  headers[:"If-Match"] = @body[:_rev] if if_match
  result = @graph.request("PATCH", "edge/#{@collection.name}/#{@body[:_key]}",
    body: body, query: query, headers: headers, key: :edge)
  return result if @server.async != false
  body2 = result.clone
  body = body.merge(body2)
  body = @body.merge(body)
  assign_attributes(body)
  return return_directly?(result) ? result : self
end