Class: Megam::Flavors
- Inherits:
-
RestAdapter
- Object
- RestAdapter
- Megam::Flavors
- Defined in:
- lib/megam/core/flavors.rb
Instance Attribute Summary
Attributes inherited from RestAdapter
#api_key, #email, #headers, #host, #master_key, #password_hash
Class Method Summary collapse
-
.create(params) ⇒ Object
Create the node via the REST API.
- .from_hash(o) ⇒ Object
- .json_create(o) ⇒ Object
- .list(params) ⇒ Object
- .remove(o) ⇒ Object
- .show(params) ⇒ Object
- .update(params) ⇒ Object
Instance Method Summary collapse
- #account_id(arg = nil) ⇒ Object
- #category(arg = []) ⇒ Object
- #cpu(arg = nil) ⇒ Object
- #create ⇒ Object
- #created_at(arg = nil) ⇒ Object
- #disk(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #flavors ⇒ Object
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(o) ⇒ Flavors
constructor
A new instance of Flavors.
- #name(arg = nil) ⇒ Object
- #org_id(arg = nil) ⇒ Object
- #price(arg = []) ⇒ Object
- #properties(arg = []) ⇒ Object
- #ram(arg = nil) ⇒ Object
- #regions(arg = []) ⇒ Object
- #remove ⇒ Object
- #some_msg(arg = nil) ⇒ Object
- #status(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
- #update ⇒ Object
- #updated_at(arg = nil) ⇒ Object
Methods inherited from RestAdapter
Constructor Details
permalink #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
permalink .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 |
permalink .from_hash(o) ⇒ Object
[View source]
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 |
permalink .json_create(o) ⇒ Object
[View source]
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 |
permalink .list(params) ⇒ Object
[View source]
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 |
permalink .remove(o) ⇒ Object
[View source]
280 281 282 283 |
# File 'lib/megam/core/flavors.rb', line 280 def self.remove(o) fav = from_hash(o) fav.remove end |
permalink .show(params) ⇒ Object
[View source]
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 |
permalink .update(params) ⇒ Object
[View source]
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
permalink #account_id(arg = nil) ⇒ Object
[View source]
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 |
permalink #category(arg = []) ⇒ Object
[View source]
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 |
permalink #cpu(arg = nil) ⇒ Object
[View source]
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 |
permalink #create ⇒ Object
[View source]
255 256 257 |
# File 'lib/megam/core/flavors.rb', line 255 def create megam_rest.post_flavors(to_hash) end |
permalink #created_at(arg = nil) ⇒ Object
[View source]
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 |
permalink #disk(arg = nil) ⇒ Object
[View source]
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 |
permalink #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 |
permalink #flavors ⇒ Object
[View source]
22 23 24 |
# File 'lib/megam/core/flavors.rb', line 22 def flavors self end |
permalink #for_json ⇒ Object
[View source]
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 |
permalink #from_hash(o) ⇒ Object
[View source]
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 |
permalink #id(arg = nil) ⇒ Object
[View source]
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 |
permalink #name(arg = nil) ⇒ Object
[View source]
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 |
permalink #org_id(arg = nil) ⇒ Object
[View source]
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 |
permalink #price(arg = []) ⇒ Object
[View source]
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 |
permalink #properties(arg = []) ⇒ Object
[View source]
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 |
permalink #ram(arg = nil) ⇒ Object
[View source]
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 |
permalink #regions(arg = []) ⇒ Object
[View source]
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 |
permalink #remove ⇒ Object
[View source]
285 286 287 |
# File 'lib/megam/core/flavors.rb', line 285 def remove megam_rest.delete_flavors(to_hash) end |
permalink #some_msg(arg = nil) ⇒ Object
[View source]
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 |
permalink #status(arg = nil) ⇒ Object
[View source]
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 |
permalink #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 |
permalink #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 |
permalink #to_s ⇒ Object
[View source]
289 290 291 |
# File 'lib/megam/core/flavors.rb', line 289 def to_s Megam::Stuff.styled_hash(to_hash) end |
permalink #update ⇒ Object
[View source]
276 277 278 |
# File 'lib/megam/core/flavors.rb', line 276 def update megam_rest.update_flavors(to_hash) end |
permalink #updated_at(arg = nil) ⇒ Object
[View source]
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 |