Module: Arango::Edge::InstanceMethods
- Defined in:
- lib/arango/edge/instance_methods.rb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/arango/edge/instance_methods.rb', line 70
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.
49
50
51
|
# File 'lib/arango/edge/instance_methods.rb', line 49
def attributes
@attributes
end
|
#database ⇒ Object
Returns the value of attribute database.
49
50
51
|
# File 'lib/arango/edge/instance_methods.rb', line 49
def database
@database
end
|
#edge_collection ⇒ Object
Returns the value of attribute edge_collection.
49
50
51
|
# File 'lib/arango/edge/instance_methods.rb', line 49
def edge_collection
@edge_collection
end
|
#graph ⇒ Object
Returns the value of attribute graph.
49
50
51
|
# File 'lib/arango/edge/instance_methods.rb', line 49
def graph
@graph
end
|
#ignore_revs ⇒ Object
Returns the value of attribute ignore_revs.
48
49
50
|
# File 'lib/arango/edge/instance_methods.rb', line 48
def ignore_revs
@ignore_revs
end
|
#server ⇒ Object
Returns the value of attribute server.
49
50
51
|
# File 'lib/arango/edge/instance_methods.rb', line 49
def server
@server
end
|
#wait_for_sync ⇒ Object
Returns the value of attribute wait_for_sync.
48
49
50
|
# File 'lib/arango/edge/instance_methods.rb', line 48
def wait_for_sync
@wait_for_sync
end
|
Instance Method Details
#create ⇒ Object
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/arango/edge/instance_methods.rb', line 109
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
153
154
155
156
157
158
159
160
|
# File 'lib/arango/edge/instance_methods.rb', line 153
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
162
163
164
|
# File 'lib/arango/edge/instance_methods.rb', line 162
def from
@from_instance ||= _get_instance(from_id)
end
|
#from=(f) ⇒ Object
170
171
172
173
|
# File 'lib/arango/edge/instance_methods.rb', line 170
def from=(f)
_set_from(f)
from_id
end
|
#from_id ⇒ Object
166
167
168
|
# File 'lib/arango/edge/instance_methods.rb', line 166
def from_id
@changed_attributes[:_from] || @attributes[:_from]
end
|
#id ⇒ Object
18
19
20
21
22
|
# File 'lib/arango/edge/instance_methods.rb', line 18
def id
i = @changed_attributes[:_id] || @attributes[:_id]
return i if i
"#{edge_collection.name}/#{key}"
end
|
#id=(i) ⇒ Object
24
25
26
|
# File 'lib/arango/edge/instance_methods.rb', line 24
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
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/arango/edge/instance_methods.rb', line 5
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
28
29
30
|
# File 'lib/arango/edge/instance_methods.rb', line 28
def key
@changed_attributes[:_key] || @attributes[:_key]
end
|
#key=(k) ⇒ Object
32
33
34
|
# File 'lib/arango/edge/instance_methods.rb', line 32
def key=(k)
@changed_attributes[:_key] = k
end
|
#reload ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/arango/edge/instance_methods.rb', line 88
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/arango/edge/instance_methods.rb', line 120
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
36
37
38
|
# File 'lib/arango/edge/instance_methods.rb', line 36
def revision
@changed_attributes[:_rev] || @attributes[:_rev]
end
|
#revision=(r) ⇒ Object
40
41
42
|
# File 'lib/arango/edge/instance_methods.rb', line 40
def revision=(r)
@changed_attributes[:_rev] = r
end
|
#same_revision? ⇒ Boolean
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/arango/edge/instance_methods.rb', line 98
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
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/arango/edge/instance_methods.rb', line 139
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
175
176
177
|
# File 'lib/arango/edge/instance_methods.rb', line 175
def to
@to_instance ||= _get_instance(to_id)
end
|
#to=(t) ⇒ Object
183
184
185
186
|
# File 'lib/arango/edge/instance_methods.rb', line 183
def to=(t)
_set_to(t)
to_id
end
|
#to_h ⇒ Object
44
45
46
|
# File 'lib/arango/edge/instance_methods.rb', line 44
def to_h
@attributes.delete_if{ |_,v| v.nil? }
end
|
#to_id ⇒ Object
179
180
181
|
# File 'lib/arango/edge/instance_methods.rb', line 179
def to_id
@changed_attributes[:_to] || @attributes[:_to]
end
|