module RightScale::Api::Gateway
Public Class Methods
new(params = {})
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 83 def initialize(params = {}) @params = parse_params(params) end
Public Instance Methods
[](name)
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 162 def [](name) try_these = [name.to_s, name.to_s.gsub(/_/,'-'), name.to_sym] if try_these.include?(:nickname) try_these += ["name", :name] end try_these.each do |t| if @params[t] return @params[t] elsif hash_of_links[t] return hash_of_links[t] end end return nil end
[]=(name,val)
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 177 def []=(name,val) try_these = [name.to_s, name.to_s.gsub(/_/,'-'), name.to_sym] if try_these.include?(:nickname) try_these += ["name", :name] end try_these.each do |t| if @params[t] @params[t] = val elsif hash_of_links[t] @params['links'].each { |link| link['href'] = val if link['rel'] == t } end end val end
actions()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 121 def actions ret = [] self.rediscover unless @params['actions'] @params['actions'].each { |action| ret << action['rel'] } ret end
hash_of_links()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 106 def hash_of_links ret = {} self.rediscover unless @params['links'] @params['links'].each { |link| ret[link['rel']] = link['href'] } if @params['links'] ret end
href()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 113 def href return @params['href'] if @params['href'] ret = nil self.rediscover unless @params['links'] @params['links'].each { |link| ret = link['href'] if link['rel'] == 'self' } ret end
load(resource)
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 194 def load(resource) mod = RightScale::Api::GatewayExtend @@gateway_resources ||= Object.constants.map do |const| klass = Object.const_get(const) (mod === klass ? klass : nil) end.compact pp @@gateway_resources if mod === resource klass = resource elsif resource.is_a?(String) or resource.is_a?(Symbol) klass = @@gateway_resources.detect do |const| [const.resource_singular_name, const.resource_plural_name].include?(resource.to_s) end elsif Class === resource raise TypeError.new("#{resource} doesn't extend #{mod}") else raise TypeError.new("can't convert #{resource.class} into supported Class") end if self[klass.resource_singular_name] return klass.load(self[klass.resource_singular_name]) elsif self[klass.resource_plural_name] return klass.load_all(self[klass.resource_plural_name]) else raise NameError.new("no resource_hrefs found for #{klass}") end end
method_missing(method_name, *args)
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 132 def method_missing(method_name, *args) puts "DEBUG: method_missing in #{self.class.to_s}: #{method_name.to_s}" if ENV['REST_CONNECT_DEBUG'] mn = method_name.to_s assignment = mn.gsub!(/=/,"") mn_dash = mn.gsub(/_/,"-") if self[mn] if assignment self[mn] = args[0] self[mn_dash] = args[0] end return self[mn] elsif self[mn_dash] if assignment self[mn_dash] = args[0] self[mn] = args[0] end return self[mn_dash] elsif self[mn.to_sym] return self[mn.to_sym] elsif assignment self[mn] = args[0] self[mn_dash] = args[0] return self[mn] else return nil warn "!!!! WARNING - called unknown method #{method_name.to_s}# with #{args.inspect}" #raise "called unknown method #{method_name.to_s}# with #{args.inspect}" end end
nickname()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 91 def nickname raise TypeError.new("@params isn't a Hash! @params.to_s=#{@params.to_s}") unless @params.is_a?(Hash) @params["nickname"] || @params["name"] end
parse_params(params = {})
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 87 def parse_params(params = {}) params end
rediscover()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 96 def rediscover self.reload if @params['href'] raise "Cannot find attribute 'nickname' or 'name' in #{self.inspect}. Aborting." unless self.nickname if self.class.filters.include?(:name) @params = self.class.find_with_filter(:name => self.nickname).first.params else @params = self.class.find_by(:name) { |n| n == self.nickname }.first.params end end
save()
click to toggle source
# File lib/rest_connection/rightscale/rightscale_api_gateway.rb, line 128 def save update end