Module: Arango::Edge::InstanceMethods
- Defined in:
- lib/arango/edge/instance_methods.rb
Overview
Arango Edge InstanceMethods
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/arango/edge/instance_methods.rb', line 72
def method_missing(name, *args, &block)
name_s = name.to_s
set_attr = false
have_attr = false
attribute_name_s = name_s.end_with?('=') ? (set_attr = true; name_s.chop) : name_s
attribute_name_y = attribute_name_s.start_with?('attribute_') ? (have_attr = true; attribute_name_s[9..-1].to_sym) : attribute_name_s.to_sym
if set_attr
return @changed_attributes[attribute_name_y] = args[0]
elsif @changed_attributes.key?(attribute_name_y)
return @changed_attributes[attribute_name_y]
elsif @attributes.key?(attribute_name_y)
return @attributes[attribute_name_y]
elsif have_attr
return nil
end
super(name, *args, &block)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
51
52
53
|
# File 'lib/arango/edge/instance_methods.rb', line 51
def attributes
@attributes
end
|
#database ⇒ Object
Returns the value of attribute database.
51
52
53
|
# File 'lib/arango/edge/instance_methods.rb', line 51
def database
@database
end
|
#edge_collection ⇒ Object
Returns the value of attribute edge_collection.
51
52
53
|
# File 'lib/arango/edge/instance_methods.rb', line 51
def edge_collection
@edge_collection
end
|
#graph ⇒ Object
Returns the value of attribute graph.
51
52
53
|
# File 'lib/arango/edge/instance_methods.rb', line 51
def graph
@graph
end
|
#ignore_revs ⇒ Object
Returns the value of attribute ignore_revs.
50
51
52
|
# File 'lib/arango/edge/instance_methods.rb', line 50
def ignore_revs
@ignore_revs
end
|
#server ⇒ Object
Returns the value of attribute server.
51
52
53
|
# File 'lib/arango/edge/instance_methods.rb', line 51
def server
@server
end
|
#wait_for_sync ⇒ Object
Returns the value of attribute wait_for_sync.
50
51
52
|
# File 'lib/arango/edge/instance_methods.rb', line 50
def wait_for_sync
@wait_for_sync
end
|
Instance Method Details
#create ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/arango/edge/instance_methods.rb', line 111
def create
params = { returnNew: true }
params[:waitForSync] = @wait_for_sync unless @wait_for_sync.nil?
@attributes = @attributes.merge(@changed_attributes)
@changed_attributes = {}
args = { collection: @edge_collection.name }
result = Arango::Requests::Document::Create.execute(server: @server, args: args, params: params, body: @attributes)
@attributes.merge!(result[:new])
self
end
|
#delete ⇒ Object
155
156
157
158
159
160
161
162
|
# File 'lib/arango/edge/instance_methods.rb', line 155
def delete
params = { waitForSync: @wait_for_sync }
= nil
= { "If-Match": @attributes[:_rev] } if !@ignore_revs && @attributes.key?(:_rev)
args = { collection: @edge_collection.name, key: @attributes[:_key] }
Arango::Requests::Document::Delete.execute(server: @server, args: args, params: params, headers: )
nil
end
|
#from ⇒ Object
164
165
166
|
# File 'lib/arango/edge/instance_methods.rb', line 164
def from
@from_instance ||= _get_instance(from_id)
end
|
#from=(f) ⇒ Object
172
173
174
175
|
# File 'lib/arango/edge/instance_methods.rb', line 172
def from=(f)
_set_from(f)
from_id
end
|
#from_id ⇒ Object
168
169
170
|
# File 'lib/arango/edge/instance_methods.rb', line 168
def from_id
@changed_attributes[:_from] || @attributes[:_from]
end
|
#id ⇒ Object
20
21
22
23
24
|
# File 'lib/arango/edge/instance_methods.rb', line 20
def id
i = @changed_attributes[:_id] || @attributes[:_id]
return i if i
"#{edge_collection.name}/#{key}"
end
|
#id=(i) ⇒ Object
26
27
28
|
# File 'lib/arango/edge/instance_methods.rb', line 26
def id=(i)
@changed_attributes[:_id] = i
end
|
#initialize(key: nil, attributes: {}, from: nil, to: nil, edge_collection:, ignore_revs: false, wait_for_sync: false) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/arango/edge/instance_methods.rb', line 7
def initialize(key: nil, attributes: {}, from: nil, to: nil, edge_collection:, ignore_revs: false, wait_for_sync: false)
@attributes = _attributes_from_arg(attributes)
@attributes[:_key] = key if key
@changed_attributes = {}
@ignore_revs = ignore_revs
@wait_for_sync = wait_for_sync
_set_from(from || from_id)
_set_to(to || to_id)
send(:edge_collection=, edge_collection)
send(:graph=, edge_collection.graph) if edge_collection.graph
end
|
#key ⇒ Object
30
31
32
|
# File 'lib/arango/edge/instance_methods.rb', line 30
def key
@changed_attributes[:_key] || @attributes[:_key]
end
|
#key=(k) ⇒ Object
34
35
36
|
# File 'lib/arango/edge/instance_methods.rb', line 34
def key=(k)
@changed_attributes[:_key] = k
end
|
#reload ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/arango/edge/instance_methods.rb', line 90
def reload
= nil
= { "If-Match": @attributes[:_rev] } if !@ignore_revs && @attributes.key?(:_rev)
args = { collection: @edge_collection.name, key: @attributes[:_key] }
result = Arango::Requests::Document::Get.execute(server: @server, headers: , args: args)
@attributes = _attributes_from_arg(result)
@changed_attributes = {}
self
end
|
#replace ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/arango/edge/instance_methods.rb', line 122
def replace
params = { returnNew: true, ignoreRevs: @ignore_revs }
params[:waitForSync] = @wait_for_sync unless @wait_for_sync.nil?
= nil
attributes = @changed_attributes
attributes[:_id] = @attributes[:_id]
attributes[:_key] = @attributes[:_key]
attributes[:_rev] = @attributes[:_rev]
attributes[:_from] = from_id
attributes[:_to] = to_id
@attributes = attributes
@changed_attributes = {}
= { "If-Match": @attributes[:_rev] } if !@ignore_revs && @attributes.key?(:_rev)
args = { collection: @edge_collection.name, key: @attributes[:_key] }
result = Arango::Requests::Document::Replace.execute(server: @server, args: args, params: params, headers: , body: @attributes)
@attributes.merge!(result[:new])
self
end
|
#revision ⇒ Object
38
39
40
|
# File 'lib/arango/edge/instance_methods.rb', line 38
def revision
@changed_attributes[:_rev] || @attributes[:_rev]
end
|
#revision=(r) ⇒ Object
42
43
44
|
# File 'lib/arango/edge/instance_methods.rb', line 42
def revision=(r)
@changed_attributes[:_rev] = r
end
|
#same_revision? ⇒ Boolean
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/arango/edge/instance_methods.rb', line 100
def same_revision?
= { "If-Match": @attributes[:_rev] }
args = { collection: @edge_collection.name, key: @attributes[:_key] }
begin
Arango::Requests::Document::Head.execute(server: @server, headers: , args: args)
rescue Error => e
return false
end
true
end
|
#save ⇒ Object
Also known as:
update
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/arango/edge/instance_methods.rb', line 141
def save
params = { returnNew: true, ignoreRevs: @ignore_revs }
params[:waitForSync] = @wait_for_sync unless @wait_for_sync.nil?
= nil
= { "If-Match": @attributes[:_rev] } if !@ignore_revs && @attributes.key?(:_rev)
changed_attributes = @changed_attributes
@changed_attributes = {}
args = { collection: @edge_collection.name, key: @attributes[:_key] }
result = Arango::Requests::Document::Update.execute(server: @server, args: args, params: params, headers: , body: changed_attributes)
@attributes.merge!(result[:new])
self
end
|
#to ⇒ Object
177
178
179
|
# File 'lib/arango/edge/instance_methods.rb', line 177
def to
@to_instance ||= _get_instance(to_id)
end
|
#to=(t) ⇒ Object
185
186
187
188
|
# File 'lib/arango/edge/instance_methods.rb', line 185
def to=(t)
_set_to(t)
to_id
end
|
#to_h ⇒ Object
46
47
48
|
# File 'lib/arango/edge/instance_methods.rb', line 46
def to_h
@attributes.delete_if{ |_,v| v.nil? }
end
|
#to_id ⇒ Object
181
182
183
|
# File 'lib/arango/edge/instance_methods.rb', line 181
def to_id
@changed_attributes[:_to] || @attributes[:_to]
end
|