module RightScale::Api::Base

Attributes

params[RW]

The params hash of attributes for direct manipulation

Public Class Methods

new(params = {}) click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_base.rb, line 333
def initialize(params = {})
  @params = params
end

Public Instance Methods

[](name) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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
method_missing(method_name, *args) click to toggle source

the following two methods are used to access the @params hash in a friendly way

# 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
    #raise "called unknown method #{method_name} with #{args.inspect}"
  end
end
reload() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_base.rb, line 341
def resource_singular_name
  self.class.to_s.underscore
end
rs_id() click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_base.rb, line 409
def rs_id
  self.href.split(/\//).last
end
save() click to toggle source
# 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