megam_api 1.5.rc1 → 1.5.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/megam/api.rb +18 -3
- data/lib/megam/api/billingtranscations.rb +40 -0
- data/lib/megam/api/eventsbilling.rb +50 -0
- data/lib/megam/api/eventscontainer.rb +50 -0
- data/lib/megam/api/{events.rb → eventsstorage.rb} +4 -5
- data/lib/megam/api/eventsvm.rb +50 -0
- data/lib/megam/api/snapshots.rb +50 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/billingtranscations.rb +244 -0
- data/lib/megam/core/billingtranscations_collection.rb +136 -0
- data/lib/megam/core/{events.rb → eventsbilling.rb} +10 -18
- data/lib/megam/core/eventsbilling_collection.rb +137 -0
- data/lib/megam/core/eventscontainer.rb +190 -0
- data/lib/megam/core/eventscontainer_collection.rb +137 -0
- data/lib/megam/core/eventsstorage.rb +172 -0
- data/lib/megam/core/eventsstorage_collection.rb +137 -0
- data/lib/megam/core/eventsvm.rb +190 -0
- data/lib/megam/core/{events_collection.rb → eventsvm_collection.rb} +38 -38
- data/lib/megam/core/json_compat.rb +36 -6
- data/lib/megam/core/snapshots.rb +184 -0
- data/lib/megam/core/snapshots_collection.rb +137 -0
- data/test/test_billingtranscations.rb +33 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +30 -0
- data/test/test_eventsstorage.rb +14 -0
- data/test/test_eventsvm.rb +30 -0
- data/test/test_snapshots.rb +32 -0
- metadata +32 -7
- data/test/test_events.rb +0 -17
@@ -14,35 +14,35 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
module Megam
|
17
|
-
class
|
17
|
+
class EventsVmCollection
|
18
18
|
include Enumerable
|
19
19
|
|
20
20
|
attr_reader :iterator
|
21
21
|
def initialize
|
22
|
-
@
|
23
|
-
@
|
22
|
+
@eventsvm = Array.new
|
23
|
+
@eventsvm_by_name = Hash.new
|
24
24
|
@insert_after_idx = nil
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
@
|
27
|
+
def all_eventsvm
|
28
|
+
@eventsvm
|
29
29
|
end
|
30
30
|
|
31
31
|
def [](index)
|
32
|
-
@
|
32
|
+
@eventsvm[index]
|
33
33
|
end
|
34
34
|
|
35
35
|
def []=(index, arg)
|
36
|
-
|
37
|
-
@
|
38
|
-
@
|
36
|
+
is_megam_eventsvm(arg)
|
37
|
+
@eventsvm[index] = arg
|
38
|
+
@eventsvm_by_name[arg.account_id] = index
|
39
39
|
end
|
40
40
|
|
41
41
|
def <<(*args)
|
42
42
|
args.flatten.each do |a|
|
43
43
|
is_megam_events(a)
|
44
|
-
@
|
45
|
-
@
|
44
|
+
@eventsvm << a
|
45
|
+
@eventsvm_by_name[a.account_id] = @eventsvm.length - 1
|
46
46
|
end
|
47
47
|
self
|
48
48
|
end
|
@@ -50,59 +50,59 @@ module Megam
|
|
50
50
|
# 'push' is an alias method to <<
|
51
51
|
alias_method :push, :<<
|
52
52
|
|
53
|
-
def insert(
|
54
|
-
|
53
|
+
def insert(eventsvm)
|
54
|
+
is_megam_eventsvm(eventsvm)
|
55
55
|
if @insert_after_idx
|
56
56
|
# in the middle of executing a run, so any nodes inserted now should
|
57
57
|
# be placed after the most recent addition done by the currently executing
|
58
58
|
# node
|
59
|
-
@
|
59
|
+
@eventsvm.insert(@insert_after_idx + 1, eventsvm)
|
60
60
|
# update name -> location mappings and register new node
|
61
|
-
@
|
62
|
-
@
|
61
|
+
@eventsvm_by_name.each_key do |key|
|
62
|
+
@eventsvm_by_name[key] += 1 if @eventsvm_by_name[key] > @insert_after_idx
|
63
63
|
end
|
64
|
-
@
|
64
|
+
@eventsvm_by_name[eventsvm.account_id] = @insert_after_idx + 1
|
65
65
|
@insert_after_idx += 1
|
66
66
|
else
|
67
|
-
@
|
68
|
-
@
|
67
|
+
@eventsvm << eventsvm
|
68
|
+
@eventsvm_by_name[eventsvm.account_id] = @eventsvm.length - 1
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
def each
|
73
|
-
@
|
74
|
-
yield
|
73
|
+
@eventsvm.each do |eventsvm|
|
74
|
+
yield eventsvm
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def each_index
|
79
|
-
@
|
79
|
+
@eventsvm.each_index do |i|
|
80
80
|
yield i
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
def empty?
|
85
|
-
@
|
85
|
+
@eventsvm.empty?
|
86
86
|
end
|
87
87
|
|
88
|
-
def lookup(
|
88
|
+
def lookup(eventsvm)
|
89
89
|
lookup_by = nil
|
90
|
-
if events.kind_of?(Megam::
|
91
|
-
lookup_by =
|
90
|
+
if events.kind_of?(Megam::EventsVm)
|
91
|
+
lookup_by = eventsvm.account_id
|
92
92
|
elsif events.kind_of?(String)
|
93
|
-
lookup_by =
|
93
|
+
lookup_by = eventsvm
|
94
94
|
else
|
95
|
-
raise ArgumentError, "Must pass a Megam::
|
95
|
+
raise ArgumentError, "Must pass a Megam::EventsVm or String to lookup"
|
96
96
|
end
|
97
|
-
res = @
|
97
|
+
res = @eventsvm_by_name[lookup_by]
|
98
98
|
unless res
|
99
99
|
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
100
100
|
end
|
101
|
-
@
|
101
|
+
@eventsvm[res]
|
102
102
|
end
|
103
103
|
|
104
104
|
def to_s
|
105
|
-
@
|
105
|
+
@eventsvm.join(", ")
|
106
106
|
end
|
107
107
|
|
108
108
|
def for_json
|
@@ -115,10 +115,10 @@ module Megam
|
|
115
115
|
|
116
116
|
def self.json_create(o)
|
117
117
|
collection = self.new()
|
118
|
-
o["results"].each do |
|
119
|
-
|
120
|
-
|
121
|
-
collection.insert(
|
118
|
+
o["results"].each do |eventsvm_list|
|
119
|
+
eventsvm_array = eventsvm_list.kind_of?(Array) ? eventsvm_list : [ eventsvm_list ]
|
120
|
+
eventsvm_array.each do |eventsvm|
|
121
|
+
collection.insert(eventsvm)
|
122
122
|
|
123
123
|
end
|
124
124
|
end
|
@@ -127,9 +127,9 @@ module Megam
|
|
127
127
|
|
128
128
|
private
|
129
129
|
|
130
|
-
def
|
131
|
-
unless arg.kind_of?(Megam::
|
132
|
-
raise ArgumentError, "Members must be Megam::
|
130
|
+
def is_megam_eventsvm(arg)
|
131
|
+
unless arg.kind_of?(Megam::EventsVm)
|
132
|
+
raise ArgumentError, "Members must be Megam::EventsVm's"
|
133
133
|
end
|
134
134
|
true
|
135
135
|
end
|
@@ -33,6 +33,8 @@ module Megam
|
|
33
33
|
MEGAM_BALANCESCOLLECTION = 'Megam::BalancesCollection'.freeze
|
34
34
|
MEGAM_BILLEDHISTORIES = 'Megam::Billedhistories'.freeze
|
35
35
|
MEGAM_BILLEDHISTORIESCOLLECTION = 'Megam::BilledhistoriesCollection'.freeze
|
36
|
+
MEGAM_BILLINGTRANSCATIONS = 'Megam::Billingtranscations'.freeze
|
37
|
+
MEGAM_BILLINGTRANSCATIONSCOLLECTION = 'Megam::BillingtranscationsCollection'.freeze
|
36
38
|
MEGAM_COMPONENTS = 'Megam::Components'.freeze
|
37
39
|
MEGAM_COMPONENTSCOLLECTION = 'Megam::ComponentsCollection'.freeze
|
38
40
|
MEGAM_DOMAIN = 'Megam::Domains'.freeze
|
@@ -46,10 +48,18 @@ module Megam
|
|
46
48
|
MEGAM_REQUESTCOLLECTION = 'Megam::RequestCollection'.freeze
|
47
49
|
MEGAM_SENSORS = 'Megam::Sensors'.freeze
|
48
50
|
MEGAM_SENSORSCOLLECTION = 'Megam::SensorsCollection'.freeze
|
51
|
+
MEGAM_SNAPSHOTS = 'Megam::Snapshots'.freeze
|
52
|
+
MEGAM_SNAPSHOTSCOLLECTION = 'Megam::SnapshotsCollection'.freeze
|
49
53
|
MEGAM_SSHKEY = 'Megam::SshKey'.freeze
|
50
54
|
MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
|
51
|
-
|
52
|
-
|
55
|
+
MEGAM_EVENTSVM = 'Megam::EventsVm'.freeze
|
56
|
+
MEGAM_EVENTSVMCOLLECTION = 'Megam::EventsVmCollection'.freeze
|
57
|
+
MEGAM_EVENTSCONTAINER = 'Megam::EventsContainer'.freeze
|
58
|
+
MEGAM_EVENTSCONTAINERCOLLECTION = 'Megam::EventsContainerCollection'.freeze
|
59
|
+
MEGAM_EVENTSBILLING = 'Megam::EventsBilling'.freeze
|
60
|
+
MEGAM_EVENTSBILLINGCOLLECTION = 'Megam::EventsBillingCollection'.freeze
|
61
|
+
MEGAM_EVENTSSTORAGE = 'Megam::EventsStorage'.freeze
|
62
|
+
MEGAM_EVENTSSTORAGECOLLECTION = 'Megam::EventsStorageCollection'.freeze
|
53
63
|
MEGAM_PROMOS = 'Megam::Promos'.freeze
|
54
64
|
|
55
65
|
class <<self
|
@@ -157,10 +167,22 @@ module Megam
|
|
157
167
|
Megam::SshKey
|
158
168
|
when MEGAM_SSHKEYCOLLECTION
|
159
169
|
Megam::SshKeyCollection
|
160
|
-
when
|
161
|
-
Megam::
|
162
|
-
when
|
163
|
-
Megam::
|
170
|
+
when MEGAM_EVENTSVM
|
171
|
+
Megam::EventsVm
|
172
|
+
when MEGAM_EVENTSVMCOLLECTION
|
173
|
+
Megam::EventsVmCollection
|
174
|
+
when MEGAM_EVENTSCONTAINER
|
175
|
+
Megam::EventsContainer
|
176
|
+
when MEGAM_EVENTSCONTAINERCOLLECTION
|
177
|
+
Megam::EventsContainerCollection
|
178
|
+
when MEGAM_EVENTSBILLING
|
179
|
+
Megam::EventsBilling
|
180
|
+
when MEGAM_EVENTSBILLINGCOLLECTION
|
181
|
+
Megam::EventsBillingCollection
|
182
|
+
when MEGAM_EVENTSSTORAGE
|
183
|
+
Megam::EventsStorage
|
184
|
+
when MEGAM_EVENTSSTORAGECOLLECTION
|
185
|
+
Megam::EventsStorageCollection
|
164
186
|
when MEGAM_MARKETPLACE
|
165
187
|
Megam::MarketPlace
|
166
188
|
when MEGAM_MARKETPLACECOLLECTION
|
@@ -177,6 +199,10 @@ module Megam
|
|
177
199
|
Megam::Sensors
|
178
200
|
when MEGAM_SENSORSCOLLECTION
|
179
201
|
Megam::SensorsCollection
|
202
|
+
when MEGAM_SNAPSHOTS
|
203
|
+
Megam::Snapshots
|
204
|
+
when MEGAM_SNAPSHOTSCOLLECTION
|
205
|
+
Megam::SnapshotsCollection
|
180
206
|
when MEGAM_BALANCES
|
181
207
|
Megam::Balances
|
182
208
|
when MEGAM_BALANCESCOLLECTION
|
@@ -185,6 +211,10 @@ module Megam
|
|
185
211
|
Megam::Billedhistories
|
186
212
|
when MEGAM_BILLEDHISTORIESCOLLECTION
|
187
213
|
Megam::BilledhistoriesCollection
|
214
|
+
when MEGAM_BILLINGTRANSCATIONS
|
215
|
+
Megam::Billingtranscations
|
216
|
+
when MEGAM_BILLINGTRANSCATIONSCOLLECTION
|
217
|
+
Megam::BillingtranscationsCollection
|
188
218
|
when MEGAM_PROMOS
|
189
219
|
Megam::Promos
|
190
220
|
else
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Megam
|
18
|
+
class Snapshots < Megam::RestAdapter
|
19
|
+
def initialize(o)
|
20
|
+
@snap_id = nil
|
21
|
+
@account_id = nil
|
22
|
+
@asm_id = nil
|
23
|
+
@org_id = nil
|
24
|
+
@name= nil
|
25
|
+
@created_at = nil
|
26
|
+
@some_msg = {}
|
27
|
+
super(o)
|
28
|
+
end
|
29
|
+
|
30
|
+
def snapshots
|
31
|
+
self
|
32
|
+
end
|
33
|
+
def snap_id(arg=nil)
|
34
|
+
if arg != nil
|
35
|
+
@snap_id = arg
|
36
|
+
else
|
37
|
+
@snap_id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def account_id(arg=nil)
|
42
|
+
if arg != nil
|
43
|
+
@account_id = arg
|
44
|
+
else
|
45
|
+
@account_id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def asm_id(arg=nil)
|
50
|
+
if arg != nil
|
51
|
+
@asm_id = arg
|
52
|
+
else
|
53
|
+
@asm_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def org_id(arg=nil)
|
58
|
+
if arg != nil
|
59
|
+
@org_id = arg
|
60
|
+
else
|
61
|
+
@org_id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def name(arg=nil)
|
66
|
+
if arg != nil
|
67
|
+
@name = arg
|
68
|
+
else
|
69
|
+
@name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def created_at(arg=nil)
|
74
|
+
if arg != nil
|
75
|
+
@created_at = arg
|
76
|
+
else
|
77
|
+
@created_at
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def error?
|
82
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def some_msg(arg=nil)
|
87
|
+
if arg != nil
|
88
|
+
@some_msg = arg
|
89
|
+
else
|
90
|
+
@some_msg
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Transform the ruby obj -> to a Hash
|
96
|
+
def to_hash
|
97
|
+
index_hash = Hash.new
|
98
|
+
index_hash["json_claz"] = self.class.name
|
99
|
+
index_hash["snap_id"] = snap_id
|
100
|
+
index_hash["account_id"] = account_id
|
101
|
+
index_hash["asm_id"] = asm_id
|
102
|
+
index_hash["org_id"] = org_id
|
103
|
+
index_hash["name"] = name
|
104
|
+
index_hash["created_at"] = created_at
|
105
|
+
index_hash["some_msg"] = some_msg
|
106
|
+
index_hash
|
107
|
+
end
|
108
|
+
|
109
|
+
# Serialize this object as a hash: called from JsonCompat.
|
110
|
+
# Verify if this called from JsonCompat during testing.
|
111
|
+
def to_json(*a)
|
112
|
+
for_json.to_json(*a)
|
113
|
+
end
|
114
|
+
|
115
|
+
def for_json
|
116
|
+
result = {
|
117
|
+
"snap_id" => snap_id,
|
118
|
+
"account_id" => account_id,
|
119
|
+
"asm_id" => asm_id,
|
120
|
+
"org_id" => org_id,
|
121
|
+
"name" => name,
|
122
|
+
"created_at" => created_at
|
123
|
+
}
|
124
|
+
result
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.json_create(o)
|
128
|
+
sps = new({})
|
129
|
+
sps.snap_id(o["snap_id"]) if o.has_key?("snap_id")
|
130
|
+
sps.account_id(o["account_id"]) if o.has_key?("account_id")
|
131
|
+
sps.asm_id(o["asm_id"]) if o.has_key?("asm_id")
|
132
|
+
sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array?
|
133
|
+
sps.name(o["name"]) if o.has_key?("name")
|
134
|
+
sps.created_at(o["created_at"]) if o.has_key?("created_at")
|
135
|
+
sps.some_msg[:code] = o["code"] if o.has_key?("code")
|
136
|
+
sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
137
|
+
sps.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
138
|
+
sps.some_msg[:links] = o["links"] if o.has_key?("links")
|
139
|
+
sps
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.from_hash(o)
|
143
|
+
sps = self.new(o)
|
144
|
+
sps.from_hash(o)
|
145
|
+
sps
|
146
|
+
end
|
147
|
+
|
148
|
+
def from_hash(o)
|
149
|
+
@snap_id = o[:snap_id] if o.has_key?(:snap_id)
|
150
|
+
@account_id = o[:account_id] if o.has_key?(:account_id)
|
151
|
+
@asm_id = o[:asm_id] if o.has_key?(:asm_id)
|
152
|
+
@org_id = o[:org_id] if o.has_key?(:org_id)
|
153
|
+
@name = o[:name] if o.has_key?(:name)
|
154
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
155
|
+
self
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.create(params)
|
159
|
+
sps = from_hash(params)
|
160
|
+
sps.create
|
161
|
+
end
|
162
|
+
|
163
|
+
# Create the node via the REST API
|
164
|
+
def create
|
165
|
+
megam_rest.post_snapshots(to_hash)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Load a account by email_p
|
169
|
+
def self.show(o)
|
170
|
+
sps = self.new(o)
|
171
|
+
sps.megam_rest.get_snapshots(o[:asm_id])
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.list(params)
|
175
|
+
sps = self.new(params)
|
176
|
+
sps.megam_rest.list_snapshots
|
177
|
+
end
|
178
|
+
|
179
|
+
def to_s
|
180
|
+
Megam::Stuff.styled_hash(to_hash)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2013-2016 Megam Systems
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Megam
|
17
|
+
class SnapshotsCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@snapshots = Array.new
|
23
|
+
@snapshots_by_name = Hash.new
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_snapshots
|
28
|
+
@snapshots
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@snapshots[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_snapshots(arg)
|
37
|
+
@snapshots[index] = arg
|
38
|
+
@snapshots_by_name[arg.account_id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_events(a)
|
44
|
+
@snapshots << a
|
45
|
+
@snapshots_by_name[a.account_id] = @snapshots.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(snapshots)
|
54
|
+
is_megam_snapshots(snapshots)
|
55
|
+
if @insert_after_idx
|
56
|
+
# in the middle of executing a run, so any nodes inserted now should
|
57
|
+
# be placed after the most recent addition done by the currently executing
|
58
|
+
# node
|
59
|
+
@snapshots.insert(@insert_after_idx + 1, snapshots)
|
60
|
+
# update name -> location mappings and register new node
|
61
|
+
@snapshots_by_name.each_key do |key|
|
62
|
+
@snapshots_by_name[key] += 1 if @snapshots_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@snapshots_by_name[snapshots.account_id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@snapshots << snapshots
|
68
|
+
@snapshots_by_name[snapshots.account_id] = @snapshots.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@snapshots.each do |snapshots|
|
74
|
+
yield snapshots
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@snapshots.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@snapshots.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(snapshots)
|
89
|
+
lookup_by = nil
|
90
|
+
if events.kind_of?(Megam::Snapshots)
|
91
|
+
lookup_by = snapshots.account_id
|
92
|
+
elsif snapshots.kind_of?(String)
|
93
|
+
lookup_by = snapshots
|
94
|
+
else
|
95
|
+
raise ArgumentError, "Must pass a Megam::Snapshots or String to lookup"
|
96
|
+
end
|
97
|
+
res = @snapshots_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@snapshots[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
@snapshots.join(", ")
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_json(*a)
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.json_create(o)
|
117
|
+
collection = self.new()
|
118
|
+
o["results"].each do |snapshots_list|
|
119
|
+
snapshots_array = snapshots_list.kind_of?(Array) ? snapshots_list : [ snapshots_list ]
|
120
|
+
snapshots_array.each do |snapshots|
|
121
|
+
collection.insert(snapshots)
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
collection
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def is_megam_snapshots(arg)
|
131
|
+
unless arg.kind_of?(Megam::Snapshots)
|
132
|
+
raise ArgumentError, "Members must be Megam::Snapshots's"
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|