Class: Megam::Flavors
Instance Attribute Summary
Attributes inherited from RestAdapter
#api_key, #email, #headers, #host, #master_key, #password_hash
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from RestAdapter
#megam_rest
Constructor Details
#initialize(o) ⇒ Flavors
Returns a new instance of Flavors.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/megam/core/flavors.rb', line 3
def initialize(o)
@id = nil
@org_id = nil
@account_id = nil
@name = nil
@cpu = nil
@ram = nil
@disk = nil
@regions = []
@price = []
@properties = []
@category = []
@status = nil
@created_at = nil
@updated_at = nil
@some_msg = {}
super(o)
end
|
Class Method Details
.create(params) ⇒ Object
Create the node via the REST API
250
251
252
253
|
# File 'lib/megam/core/flavors.rb', line 250
def self.create(params)
fav = from_hash(params)
fav.create
end
|
.from_hash(o) ⇒ Object
225
226
227
228
229
|
# File 'lib/megam/core/flavors.rb', line 225
def self.from_hash(o)
sps = self.new(o)
sps.from_hash(o)
sps
end
|
.json_create(o) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/megam/core/flavors.rb', line 202
def self.json_create(o)
fav = new({})
fav.id(o['id']) if o.key?('id')
fav.org_id(o['org_id']) if o.key?('org_id')
fav.account_id(o["account_id"]) if o.has_key?("account_id")
fav.name(o['name']) if o.key?('name')
fav.cpu(o['cpu']) if o.key?('cpu')
fav.ram(o['ram']) if o.key?('ram')
fav.disk(o['disk']) if o.key?('disk')
fav.regions(o['regions']) if o.key?('regions')
fav.price(o['price']) if o.key?('price')
fav.properties(o['properties']) if o.key?('properties')
fav.category(o['category']) if o.key?('category')
fav.status(o['status']) if o.key?('status')
fav.created_at(o['created_at']) if o.key?('created_at')
fav.updated_at(o['updated_at']) if o.key?('updated_at')
fav.some_msg[:code] = o["code"] if o.has_key?("code")
fav.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
fav.some_msg[:msg]= o["msg"] if o.has_key?("msg")
fav.some_msg[:links] = o["links"] if o.has_key?("links")
fav
end
|
.list(params) ⇒ Object
261
262
263
264
|
# File 'lib/megam/core/flavors.rb', line 261
def self.list(params)
fav = self.new(params)
fav.megam_rest.get_flavors
end
|
.remove(o) ⇒ Object
280
281
282
283
|
# File 'lib/megam/core/flavors.rb', line 280
def self.remove(o)
fav = from_hash(o)
fav.remove
end
|
.show(params) ⇒ Object
266
267
268
269
|
# File 'lib/megam/core/flavors.rb', line 266
def self.show(params)
fav = self.new(params)
fav.megam_rest.get_one_flavor(params[:id])
end
|
.update(params) ⇒ Object
271
272
273
274
|
# File 'lib/megam/core/flavors.rb', line 271
def self.update(params)
fav = from_hash(params)
fav.update
end
|
Instance Method Details
#account_id(arg = nil) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/megam/core/flavors.rb', line 42
def account_id(arg=nil)
if arg != nil
@account_id = arg
else
@account_id
end
end
|
#category(arg = []) ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/megam/core/flavors.rb', line 107
def category(arg = [])
if arg != []
@category = arg
else
@category
end
end
|
#cpu(arg = nil) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/megam/core/flavors.rb', line 59
def cpu(arg = nil)
if arg != nil
@cpu = arg
else
@cpu
end
end
|
#create ⇒ Object
255
256
257
|
# File 'lib/megam/core/flavors.rb', line 255
def create
megam_rest.post_flavors(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/megam/core/flavors.rb', line 123
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#disk(arg = nil) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/megam/core/flavors.rb', line 75
def disk(arg = nil)
if arg != nil
@disk = arg
else
@disk
end
end
|
#error? ⇒ Boolean
139
140
141
|
# File 'lib/megam/core/flavors.rb', line 139
def error?
crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
end
|
#flavors ⇒ Object
22
23
24
|
# File 'lib/megam/core/flavors.rb', line 22
def flavors
self
end
|
#for_json ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/megam/core/flavors.rb', line 181
def for_json
result = {
'id' => id,
'account_id' => account_id,
'name' => name,
'org_id' => org_id,
'cpu' => cpu,
'ram' => ram,
'disk' => disk,
'regions' => regions,
'price' => price,
'properties' => properties,
'category' => category,
'status' => status,
'created_at' => created_at,
'updated_at' => updated_at
}
result
end
|
#from_hash(o) ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/megam/core/flavors.rb', line 231
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@org_id = o[:org_id] if o.has_key?(:org_id)
@account_id = o[:account_id] if o.has_key?(:account_id)
@name = o[:name] if o.has_key?(:name)
@cpu = o[:cpu] if o.has_key?(:cpu)
@ram = o[:ram] if o.has_key?(:ram)
@disk = o[:disk] if o.has_key?(:disk)
@regions = o[:regions] if o.has_key?(:regions)
@price = o[:price] if o.has_key?(:price)
@properties = o[:properties] if o.has_key?(:properties)
@category = o[:category] if o.has_key?(:category)
@status = o[:status] if o.has_key?(:status)
@created_at = o[:created_at] if o.has_key?(:created_at)
@updated_at = o[:updated_at] if o.has_key?(:updated_at)
self
end
|
#id(arg = nil) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/megam/core/flavors.rb', line 26
def id(arg = nil)
if arg != nil
@id = arg
else
@id
end
end
|
#name(arg = nil) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/megam/core/flavors.rb', line 50
def name(arg = nil)
if arg != nil
@name = arg
else
@name
end
end
|
#org_id(arg = nil) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/megam/core/flavors.rb', line 34
def org_id(arg = nil)
if arg != nil
@org_id = arg
else
@org_id
end
end
|
#price(arg = []) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/megam/core/flavors.rb', line 91
def price(arg = [])
if arg != []
@price = arg
else
@price
end
end
|
#properties(arg = []) ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/megam/core/flavors.rb', line 99
def properties(arg = [])
if arg != []
@properties = arg
else
@properties
end
end
|
#ram(arg = nil) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/megam/core/flavors.rb', line 67
def ram(arg = nil)
if arg != nil
@ram = arg
else
@ram
end
end
|
#regions(arg = []) ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/megam/core/flavors.rb', line 83
def regions(arg = [])
if arg != []
@regions = arg
else
@regions
end
end
|
#remove ⇒ Object
285
286
287
|
# File 'lib/megam/core/flavors.rb', line 285
def remove
megam_rest.delete_flavors(to_hash)
end
|
#some_msg(arg = nil) ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/megam/core/flavors.rb', line 144
def some_msg(arg=nil)
if arg != nil
@some_msg = arg
else
@some_msg
end
end
|
#status(arg = nil) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/megam/core/flavors.rb', line 115
def status(arg=nil)
if arg != nil
@status = arg
else
@status
end
end
|
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/megam/core/flavors.rb', line 154
def to_hash
index_hash = Hash.new
index_hash['json_claz'] = self.class.name
index_hash['id'] = id
index_hash['org_id'] = org_id
index_hash["account_id"] = account_id
index_hash['name'] = name
index_hash['cpu'] = cpu
index_hash['ram'] = ram
index_hash['disk'] = disk
index_hash['regions'] = regions
index_hash['price'] = price
index_hash['properties'] = properties
index_hash['category'] = category
index_hash['status'] = status
index_hash['created_at'] = created_at
index_hash['updated_at'] = updated_at
index_hash["some_msg"] = some_msg
index_hash
end
|
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
177
178
179
|
# File 'lib/megam/core/flavors.rb', line 177
def to_json(*a)
for_json.to_json(*a)
end
|
#update ⇒ Object
276
277
278
|
# File 'lib/megam/core/flavors.rb', line 276
def update
megam_rest.update_flavors(to_hash)
end
|
#updated_at(arg = nil) ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/megam/core/flavors.rb', line 131
def updated_at(arg=nil)
if arg != nil
@updated_at = arg
else
@updated_at
end
end
|