Module: SoftLayer

Defined in:
lib/softlayer.rb,
lib/softlayer/util.rb,
lib/softlayer/baseclass.rb

Defined Under Namespace

Classes: BaseClass, Exception, ObjectMask, Param, ResultLimit

Constant Summary collapse

DEFAULTBASE =
SoftLayer::BaseClass

Class Method Summary collapse

Class Method Details

.ClassFactory(args) ⇒ Object

Create a Ruby class to match an SLAPI WSDL endpoint. Args:

class

The name of the class to create in Ruby format.

parent

The parent namespace to add the class to (this should be somewere in SoftLayer; optional).

base

A substitute base class (otherwise SoftLayer::Base)

This recursively walks up class creating them as needed, so SoftLayer::Dns::Domain will create classes for Dns and Domain (even though the Dns class will never be used).



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/softlayer.rb', line 78

def SoftLayer::ClassFactory(args)
  cname = args[:class]
  parent = args[:parent] unless args[:parent].nil?
  base = args[:base]
  base = DEFAULTBASE if base.nil?

  cary = cname.split('::')
  parent = const_get(cary.shift) if parent.nil? # This should always be SoftLayer, but maybe not...
  cur = cary.shift
  newclass = nil
  unless parent.const_defined?(cur)
    newclass = SoftLayer::makeSLAPIKlass(:class => cur, :parent => parent, :base => base)
  else
    newclass = parent.const_get(cur)
  end
  return newclass if cary.empty?

  left = cary.join('::')
  k = SoftLayer::ClassFactory(:class => left, :parent => newclass, :base => base) 
  return k
end

.declareClasses(args) ⇒ Object

Declare SLAPI clases. Args take class names in two forms:

soap

Service names in SOAP format (example: SoftLayer_Account)

ruby

Class names in Ruby format (example: SoftLayer::Account)

base

A substitute base class (otherwise SoftLayer::Base)

Creates the class, and retrieves and caches the endpoint WSDL.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/softlayer.rb', line 53

def SoftLayer::declareClasses(args)
  classes = args[:ruby]
  services = args[:soap]
  base = args[:base]

  unless (services.nil? || services.empty?)
    services.each do |s|
      c = s.gsub(/_/,'::')
      classes.push(c)
    end
  end

  classes.each do |cstr|
    k = SoftLayer::ClassFactory(:class => cstr, :base => base)
    k.cacheWSDL
  end
end

.makeSLAPIKlass(args) ⇒ Object

This really creates the class.

class

The name of the class to create in Ruby format.

parent

The parent namespace to add the class to (this should be somewhere in SoftLayer, not optional).

base

A substitute base class (otherwise SoftLayer::Base)



104
105
106
107
108
109
110
111
112
# File 'lib/softlayer.rb', line 104

def SoftLayer::makeSLAPIKlass(args)
  cname = args[:class]
  parent = args[:parent]
  base = args[:base]
  realKlassName = "#{cname}"
  klass = Class.new base do ; end
  parent.const_set realKlassName, klass
  return klass
end