virtengine_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/lib/megam/api.rb +329 -0
- data/lib/megam/api/accounts.rb +96 -0
- data/lib/megam/api/addons.rb +27 -0
- data/lib/megam/api/assemblies.rb +49 -0
- data/lib/megam/api/assembly.rb +56 -0
- data/lib/megam/api/backups.rb +57 -0
- data/lib/megam/api/balances.rb +45 -0
- data/lib/megam/api/billedhistories.rb +35 -0
- data/lib/megam/api/billingtransactions.rb +25 -0
- data/lib/megam/api/components.rb +24 -0
- data/lib/megam/api/credits.rb +34 -0
- data/lib/megam/api/disks.rb +44 -0
- data/lib/megam/api/domains.rb +25 -0
- data/lib/megam/api/errors.rb +29 -0
- data/lib/megam/api/eventsall.rb +36 -0
- data/lib/megam/api/eventsbilling.rb +35 -0
- data/lib/megam/api/eventscontainer.rb +35 -0
- data/lib/megam/api/eventsmarketplace.rb +35 -0
- data/lib/megam/api/eventsstorage.rb +24 -0
- data/lib/megam/api/eventsvm.rb +35 -0
- data/lib/megam/api/flavors.rb +56 -0
- data/lib/megam/api/license.rb +26 -0
- data/lib/megam/api/marketplaces.rb +68 -0
- data/lib/megam/api/organizations.rb +50 -0
- data/lib/megam/api/promos.rb +18 -0
- data/lib/megam/api/quotas.rb +47 -0
- data/lib/megam/api/rawimages.rb +36 -0
- data/lib/megam/api/reports.rb +24 -0
- data/lib/megam/api/requests.rb +36 -0
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/snapshots.rb +46 -0
- data/lib/megam/api/sshkeys.rb +35 -0
- data/lib/megam/api/subscriptions.rb +26 -0
- data/lib/megam/api/version.rb +6 -0
- data/lib/megam/core/account.rb +245 -0
- data/lib/megam/core/account_collection.rb +122 -0
- data/lib/megam/core/addons.rb +169 -0
- data/lib/megam/core/addons_collection.rb +121 -0
- data/lib/megam/core/assemblies.rb +191 -0
- data/lib/megam/core/assemblies_collection.rb +122 -0
- data/lib/megam/core/assembly.rb +226 -0
- data/lib/megam/core/assembly_collection.rb +122 -0
- data/lib/megam/core/backups.rb +259 -0
- data/lib/megam/core/backups_collection.rb +122 -0
- data/lib/megam/core/balances.rb +187 -0
- data/lib/megam/core/balances_collection.rb +121 -0
- data/lib/megam/core/billedhistories.rb +190 -0
- data/lib/megam/core/billedhistories_collection.rb +121 -0
- data/lib/megam/core/billingtransactions.rb +214 -0
- data/lib/megam/core/billingtransactions_collection.rb +122 -0
- data/lib/megam/core/components.rb +326 -0
- data/lib/megam/core/components_collection.rb +123 -0
- data/lib/megam/core/credits.rb +146 -0
- data/lib/megam/core/credits_collection.rb +121 -0
- data/lib/megam/core/disks.rb +199 -0
- data/lib/megam/core/disks_collection.rb +122 -0
- data/lib/megam/core/domain_collection.rb +122 -0
- data/lib/megam/core/domains.rb +118 -0
- data/lib/megam/core/error.rb +70 -0
- data/lib/megam/core/eventsall.rb +186 -0
- data/lib/megam/core/eventsall_collection.rb +122 -0
- data/lib/megam/core/eventsbilling.rb +174 -0
- data/lib/megam/core/eventsbilling_collection.rb +122 -0
- data/lib/megam/core/eventscontainer.rb +187 -0
- data/lib/megam/core/eventscontainer_collection.rb +122 -0
- data/lib/megam/core/eventsmarketplace.rb +187 -0
- data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
- data/lib/megam/core/eventsstorage.rb +156 -0
- data/lib/megam/core/eventsstorage_collection.rb +122 -0
- data/lib/megam/core/eventsvm.rb +187 -0
- data/lib/megam/core/eventsvm_collection.rb +122 -0
- data/lib/megam/core/flavors.rb +294 -0
- data/lib/megam/core/flavors_collection.rb +121 -0
- data/lib/megam/core/json_compat.rb +289 -0
- data/lib/megam/core/konipai.rb +42 -0
- data/lib/megam/core/license.rb +101 -0
- data/lib/megam/core/license_collection.rb +122 -0
- data/lib/megam/core/log.rb +19 -0
- data/lib/megam/core/marketplace.rb +308 -0
- data/lib/megam/core/marketplace_collection.rb +123 -0
- data/lib/megam/core/monologger.rb +89 -0
- data/lib/megam/core/organizations.rb +142 -0
- data/lib/megam/core/organizations_collection.rb +121 -0
- data/lib/megam/core/promos.rb +145 -0
- data/lib/megam/core/quotas.rb +215 -0
- data/lib/megam/core/quotas_collection.rb +121 -0
- data/lib/megam/core/rawimages.rb +194 -0
- data/lib/megam/core/rawimages_collection.rb +121 -0
- data/lib/megam/core/reports.rb +176 -0
- data/lib/megam/core/reports_collection.rb +121 -0
- data/lib/megam/core/request.rb +197 -0
- data/lib/megam/core/request_collection.rb +121 -0
- data/lib/megam/core/rest_adapter.rb +44 -0
- data/lib/megam/core/sensors.rb +141 -0
- data/lib/megam/core/sensors_collection.rb +121 -0
- data/lib/megam/core/snapshots.rb +268 -0
- data/lib/megam/core/snapshots_collection.rb +122 -0
- data/lib/megam/core/sshkey.rb +173 -0
- data/lib/megam/core/sshkey_collection.rb +122 -0
- data/lib/megam/core/stuff.rb +22 -0
- data/lib/megam/core/subscriptions.rb +167 -0
- data/lib/megam/core/subscriptions_collection.rb +121 -0
- data/lib/megam/core/text.rb +87 -0
- data/lib/megam/core/text_formatter.rb +64 -0
- data/lib/megam/mixins/assemblies.rb +16 -0
- data/lib/megam/mixins/assembly.rb +59 -0
- data/lib/megam/mixins/common_deployable.rb +78 -0
- data/lib/megam/mixins/components.rb +182 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +23 -0
- data/lib/megam/mixins/policies.rb +27 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/mixins/test_assemblies.rb +113 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +19 -0
- data/test/test_accounts.rb +127 -0
- data/test/test_addons.rb +26 -0
- data/test/test_assemblies.rb +88 -0
- data/test/test_assembly.rb +37 -0
- data/test/test_backups.rb +29 -0
- data/test/test_balances.rb +38 -0
- data/test/test_billedhistories.rb +30 -0
- data/test/test_billingtranscations.rb +35 -0
- data/test/test_components.rb +42 -0
- data/test/test_credits.rb +28 -0
- data/test/test_disks.rb +25 -0
- data/test/test_domains.rb +29 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +26 -0
- data/test/test_eventsstorage.rb +12 -0
- data/test/test_eventsvm.rb +26 -0
- data/test/test_helper.rb +77 -0
- data/test/test_marketplaces.rb +38 -0
- data/test/test_organizations.rb +45 -0
- data/test/test_promos.rb +11 -0
- data/test/test_quotas.rb +33 -0
- data/test/test_reports.rb +32 -0
- data/test/test_requests.rb +95 -0
- data/test/test_sensors.rb +50 -0
- data/test/test_snapshots.rb +30 -0
- data/test/test_sshkeys.rb +50 -0
- data/test/test_subscriptions.rb +22 -0
- metadata +325 -0
@@ -0,0 +1,145 @@
|
|
1
|
+
module Megam
|
2
|
+
class Promos < Megam::RestAdapter
|
3
|
+
def initialize(email=nil, api_key=nil, host=nil)
|
4
|
+
@id = nil
|
5
|
+
@code = nil
|
6
|
+
@amount = nil
|
7
|
+
@created_at = nil
|
8
|
+
@some_msg = {}
|
9
|
+
super(email, api_key, host)
|
10
|
+
end
|
11
|
+
|
12
|
+
def promos
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def id(arg=nil)
|
17
|
+
if arg != nil
|
18
|
+
@id = arg
|
19
|
+
else
|
20
|
+
@id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def code(arg=nil)
|
25
|
+
if arg != nil
|
26
|
+
@code = arg
|
27
|
+
else
|
28
|
+
@code
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def amount(arg=nil)
|
33
|
+
if arg != nil
|
34
|
+
@amount = arg
|
35
|
+
else
|
36
|
+
@amount
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def created_at(arg=nil)
|
41
|
+
if arg != nil
|
42
|
+
@created_at = arg
|
43
|
+
else
|
44
|
+
@created_at
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
def some_msg(arg=nil)
|
51
|
+
if arg != nil
|
52
|
+
@some_msg = arg
|
53
|
+
else
|
54
|
+
@some_msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def error?
|
59
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Transform the ruby obj -> to a Hash
|
63
|
+
def to_hash
|
64
|
+
index_hash = Hash.new
|
65
|
+
index_hash["json_claz"] = self.class.name
|
66
|
+
index_hash["id"] = id
|
67
|
+
index_hash["code"] = code
|
68
|
+
index_hash["amount"] = amount
|
69
|
+
index_hash["created_at"] = created_at
|
70
|
+
index_hash
|
71
|
+
end
|
72
|
+
|
73
|
+
# Serialize this object as a hash: called from JsonCompat.
|
74
|
+
# Verify if this called from JsonCompat during testing.
|
75
|
+
def to_json(*a)
|
76
|
+
for_json.to_json(*a)
|
77
|
+
end
|
78
|
+
|
79
|
+
def for_json
|
80
|
+
result = {
|
81
|
+
"id" => id,
|
82
|
+
"code" => code,
|
83
|
+
"amount" => amount,
|
84
|
+
"created_at" => created_at
|
85
|
+
}
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.json_create(o)
|
90
|
+
promos = new
|
91
|
+
promos.id(o["id"]) if o.has_key?("id")
|
92
|
+
promos.code(o["code"]) if o.has_key?("code")
|
93
|
+
promos.amount(o["amount"]) if o.has_key?("amount")
|
94
|
+
promos.created_at(o["created_at"]) if o.has_key?("created_at")
|
95
|
+
#success or error
|
96
|
+
promos.some_msg[:code] = o["code"] if o.has_key?("code")
|
97
|
+
promos.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
98
|
+
promos.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
99
|
+
promos.some_msg[:links] = o["links"] if o.has_key?("links")
|
100
|
+
promos
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
|
104
|
+
promos = self.new(tmp_email, tmp_api_key, tmp_host)
|
105
|
+
promos.from_hash(o)
|
106
|
+
promos
|
107
|
+
end
|
108
|
+
|
109
|
+
def from_hash(o)
|
110
|
+
@id = o[:id] if o.has_key?(:id)
|
111
|
+
@code = o[:name] if o.has_key?(:name)
|
112
|
+
@amount = o[:credit] if o.has_key?(:credit)
|
113
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.create(params)
|
118
|
+
promo = from_hash(params,params["email"], params["api_key"], params["host"])
|
119
|
+
promo.create
|
120
|
+
end
|
121
|
+
|
122
|
+
# Create the predef via the REST API
|
123
|
+
def create
|
124
|
+
megam_rest.post_promos(to_hash) #WONT BE USED AS OF NOW
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.list(params)
|
128
|
+
promos = self.new(params["email"], params["api_key"], params["host"])
|
129
|
+
promos.megam_rest.get_promos
|
130
|
+
end
|
131
|
+
|
132
|
+
# Show a particular promo by name,
|
133
|
+
# Megam::Promos
|
134
|
+
def self.show(params)
|
135
|
+
pre = self.new(params["email"], params["api_key"], params["host"])
|
136
|
+
pre.megam_rest.get_promos(params["code"])
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def to_s
|
141
|
+
Megam::Stuff.styled_hash(to_hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
module Megam
|
2
|
+
class Quotas < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@account_id = nil
|
6
|
+
@name = nil
|
7
|
+
@cost = nil
|
8
|
+
@allowed = nil
|
9
|
+
@allocated_to = nil
|
10
|
+
@quota_type = nil
|
11
|
+
@status = nil
|
12
|
+
@inputs = []
|
13
|
+
@created_at = nil
|
14
|
+
@updated_at = nil
|
15
|
+
super(o)
|
16
|
+
end
|
17
|
+
|
18
|
+
def quotas
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def id(arg = nil)
|
23
|
+
if !arg.nil?
|
24
|
+
@id = arg
|
25
|
+
else
|
26
|
+
@id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def account_id(arg=nil)
|
31
|
+
if arg != nil
|
32
|
+
@account_id = arg
|
33
|
+
else
|
34
|
+
@account_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def name(arg = nil)
|
39
|
+
if !arg.nil?
|
40
|
+
@name = arg
|
41
|
+
else
|
42
|
+
@name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def allowed(arg = nil)
|
47
|
+
if !arg.nil?
|
48
|
+
@allowed = arg
|
49
|
+
else
|
50
|
+
@allowed
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def allocated_to(arg = nil)
|
55
|
+
if !arg.nil?
|
56
|
+
@allocated_to = arg
|
57
|
+
else
|
58
|
+
@allocated_to
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def inputs(arg = [])
|
63
|
+
if arg != []
|
64
|
+
@inputs = arg
|
65
|
+
else
|
66
|
+
@inputs
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def quota_type(arg = nil)
|
71
|
+
if !arg.nil?
|
72
|
+
@quota_type = arg
|
73
|
+
else
|
74
|
+
@quota_type
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def status(arg = nil)
|
79
|
+
if !arg.nil?
|
80
|
+
@status = arg
|
81
|
+
else
|
82
|
+
@status
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def created_at(arg = nil)
|
87
|
+
if !arg.nil?
|
88
|
+
@created_at = arg
|
89
|
+
else
|
90
|
+
@created_at
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def updated_at(arg = nil)
|
95
|
+
if !arg.nil?
|
96
|
+
@updated_at = arg
|
97
|
+
else
|
98
|
+
@updated_at
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def error?
|
103
|
+
crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
|
104
|
+
end
|
105
|
+
|
106
|
+
# Transform the ruby obj -> to a Hash
|
107
|
+
def to_hash
|
108
|
+
index_hash = {}
|
109
|
+
index_hash['json_claz'] = self.class.name
|
110
|
+
index_hash['id'] = id
|
111
|
+
index_hash["account_id"] = account_id
|
112
|
+
index_hash['name'] = name
|
113
|
+
index_hash['allowed'] = allowed
|
114
|
+
index_hash['allocated_to'] = allocated_to
|
115
|
+
index_hash['quota_type'] = quota_type
|
116
|
+
index_hash['status'] = status
|
117
|
+
index_hash['inputs'] = inputs
|
118
|
+
index_hash['created_at'] = created_at
|
119
|
+
index_hash['updated_at'] = updated_at
|
120
|
+
index_hash
|
121
|
+
end
|
122
|
+
|
123
|
+
# Serialize this object as a hash: called from JsonCompat.
|
124
|
+
# Verify if this called from JsonCompat during testing.
|
125
|
+
def to_json(*a)
|
126
|
+
for_json.to_json(*a)
|
127
|
+
end
|
128
|
+
|
129
|
+
def for_json
|
130
|
+
result = {
|
131
|
+
'id' => id,
|
132
|
+
'account_id' => account_id,
|
133
|
+
'name' => name,
|
134
|
+
'allowed' => allowed,
|
135
|
+
'allocated_to' => allocated_to,
|
136
|
+
'inputs' => inputs,
|
137
|
+
'quota_type' => quota_type,
|
138
|
+
'status' => status,
|
139
|
+
'created_at' => created_at,
|
140
|
+
'updated_at' => updated_at
|
141
|
+
}
|
142
|
+
|
143
|
+
result
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.json_create(o)
|
147
|
+
quo = new({})
|
148
|
+
quo.id(o['id']) if o.key?('id')
|
149
|
+
quo.account_id(o["account_id"]) if o.has_key?("account_id")
|
150
|
+
quo.name(o['name']) if o.key?('name')
|
151
|
+
quo.allowed(o['allowed']) if o.key?('allowed')
|
152
|
+
quo.allocated_to(o['allocated_to']) if o.key?('allocated_to') # this will be an array? can hash store array?
|
153
|
+
quo.inputs(o['inputs']) if o.key?('inputs')
|
154
|
+
quo.quota_type(o['quota_type']) if o.key?('quota_type')
|
155
|
+
quo.status(o['status']) if o.key?('status')
|
156
|
+
quo.created_at(o['created_at']) if o.key?('created_at')
|
157
|
+
quo.updated_at(o['updated_at']) if o.key?('updated_at')
|
158
|
+
quo
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.from_hash(o)
|
162
|
+
quo = new(o)
|
163
|
+
quo.from_hash(o)
|
164
|
+
quo
|
165
|
+
end
|
166
|
+
|
167
|
+
def from_hash(o)
|
168
|
+
@id = o['id'] if o.key?('id')
|
169
|
+
@account_id = o["account_id"] if o.has_key?("account_id")
|
170
|
+
@name = o['name'] if o.key?('name')
|
171
|
+
@allowed = o['allowed'] if o.key?('allowed')
|
172
|
+
@allocated_to = o['allocated_to'] if o.key?('allocated_to')
|
173
|
+
@inputs = o['inputs'] if o.key?('inputs')
|
174
|
+
@quota_type = o['quota_type'] if o.key?('quota_type')
|
175
|
+
@status = o['status'] if o.key?('status')
|
176
|
+
@created_at = o['created_at'] if o.key?('created_at')
|
177
|
+
@updated_at = o['updated_at'] if o.key?('updated_at')
|
178
|
+
self
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def self.show(params)
|
183
|
+
quo = new(params)
|
184
|
+
quo.megam_rest.get_one_quota(params['id'])
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.update(params)
|
188
|
+
quo = from_hash(params)
|
189
|
+
quo.update
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.list(params)
|
193
|
+
quo = self.new(params)
|
194
|
+
quo.megam_rest.list_quotas
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.create(params)
|
198
|
+
quo = from_hash(params)
|
199
|
+
quo.create
|
200
|
+
end
|
201
|
+
|
202
|
+
def create
|
203
|
+
megam_rest.post_quotas(to_hash)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Create the node via the REST API
|
207
|
+
def update
|
208
|
+
megam_rest.update_quotas(to_hash)
|
209
|
+
end
|
210
|
+
|
211
|
+
def to_s
|
212
|
+
Megam::Stuff.styled_hash(to_hash)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Megam
|
2
|
+
class QuotasCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@quotas = Array.new
|
8
|
+
@quotas_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def all_quotas
|
13
|
+
@quotas
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](index)
|
17
|
+
@quotas[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_quotas(arg)
|
22
|
+
@quotas[index] = arg
|
23
|
+
@quotas_by_name[arg.id] = index
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_quotas(a)
|
29
|
+
@quotas << a
|
30
|
+
@quotas_by_name[a.id] = @quotas.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(quotas)
|
39
|
+
is_megam_quotas(quotas)
|
40
|
+
if @insert_after_idx
|
41
|
+
# in the middle of executing a run, so any nodes inserted now should
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
43
|
+
# node
|
44
|
+
@quotas.insert(@insert_after_idx + 1, quotas)
|
45
|
+
# update name -> location mappings and register new node
|
46
|
+
@quotas_by_name.each_key do |key|
|
47
|
+
@quotas_by_name[key] += 1 if @quotas_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@quotas_by_name[quotas.id] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@quotas << quotas
|
53
|
+
@quotas_by_name[quotas.id] = @quotas.length - 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
@quotas.each do |quotas|
|
59
|
+
yield quotas
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each_index
|
64
|
+
@quotas.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
@quotas.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup(quotas)
|
74
|
+
lookup_by = nil
|
75
|
+
if quotas.kind_of?(Megam::Quotas)
|
76
|
+
lookup_by = quotas.id
|
77
|
+
elsif quotas.kind_of?(String)
|
78
|
+
lookup_by = quotas
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::Quotas or String to lookup"
|
81
|
+
end
|
82
|
+
res = @quotas_by_name[lookup_by]
|
83
|
+
unless res
|
84
|
+
raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
|
85
|
+
end
|
86
|
+
@quotas[res]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
@quotas.join(", ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |quotas_list|
|
104
|
+
quotas_array = quotas_list.kind_of?(Array) ? quotas_list : [ quotas_list ]
|
105
|
+
quotas_array.each do |quotas|
|
106
|
+
collection.insert(quotas)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
collection
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def is_megam_quotas(arg)
|
115
|
+
unless arg.kind_of?(Megam::Quotas)
|
116
|
+
raise ArgumentError, "Members must be Megam::Quotas's"
|
117
|
+
end
|
118
|
+
true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|