Module: RightScale::Api::Base
- Includes:
- BaseConnection
- Included in:
- AlertSpec, AlertSpecSubject, AuditEntry, Credential, Deployment, Ec2EbsSnapshot, Ec2EbsVolume, Ec2ElasticIp, Ec2SecurityGroup, Ec2ServerArray, Ec2SshKey, Ec2SshKeyInternal, Executable, Instance, Macro, MultiCloudImage, MultiCloudImageCloudSettingInternal, MultiCloudImageInternal, Gateway, RightScript, RightScriptAttachmentInternal, RightScriptInternal, RsInternal, S3Bucket, Server, ServerEc2EbsVolume, ServerInternal, ServerTemplate, ServerTemplateInternal, SqsQueue, Status, Tag, VpcDhcpOption
- Defined in:
- lib/rest_connection/rightscale/rightscale_api_base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#connection
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
the following two methods are used to access the @params hash in a friendly way
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 361
def method_missing(method_name, *args)
mn = method_name.to_s
assignment = mn.gsub!(/=/,"")
mn_dash = mn.gsub(/_/,"-")
if @params[mn]
if assignment
@params[mn] = args[0]
@params[mn_dash] = args[0]
end
return @params[mn]
elsif @params[mn_dash]
if assignment
@params[mn_dash] = args[0]
@params[mn] = args[0]
end
return @params[mn_dash]
elsif @params[mn.to_sym]
return @params[mn.to_sym]
elsif assignment
@params[mn] = args[0]
@params[mn_dash] = args[0]
return @params[mn]
else
return nil
end
end
|
Instance Attribute Details
#params ⇒ Object
The params hash of attributes for direct manipulation
332
333
334
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 332
def params
@params
end
|
Instance Method Details
#[](name) ⇒ Object
389
390
391
392
393
394
395
396
397
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 389
def [](name)
try_these = [name.to_s, name.to_s.gsub(/_/,'-'), name.to_sym]
try_these.each do |t|
if @params[t]
return @params[t]
end
end
nil
end
|
#[]=(name, val) ⇒ Object
399
400
401
402
403
404
405
406
407
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 399
def []=(name,val)
try_these = [name.to_s, name.to_s.gsub(/_/,'-'), name.to_sym]
try_these.each do |t|
if @params[t]
@params[t] = val
end
end
val
end
|
#destroy ⇒ Object
355
356
357
358
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 355
def destroy
my_href = URI.parse(self.href)
connection.delete(my_href.path)
end
|
#initialize(params = {}) ⇒ Object
333
334
335
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 333
def initialize(params = {})
@params = params
end
|
#reload ⇒ Object
350
351
352
353
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 350
def reload
uri = URI.parse(self.href)
@params ? @params.merge!(connection.get(uri.path)) : @params = connection.get(uri.path)
end
|
#resource_plural_name ⇒ Object
337
338
339
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 337
def resource_plural_name
self.class.to_s.underscore.pluralize
end
|
#resource_singular_name ⇒ Object
341
342
343
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 341
def resource_singular_name
self.class.to_s.underscore
end
|
#rs_id ⇒ Object
409
410
411
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 409
def rs_id
self.href.split(/\//).last
end
|
#save ⇒ Object
345
346
347
348
|
# File 'lib/rest_connection/rightscale/rightscale_api_base.rb', line 345
def save
uri = URI.parse(self.href)
connection.put(uri.path, resource_singular_name.to_sym => @params)
end
|