Class: IControl::Base::Struct

Inherits:
Object
  • Object
show all
Defined in:
lib/icontrol/base/struct.rb

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Attribute Details

+ (Object) attributes

Returns the value of attribute attributes



9
10
11
# File 'lib/icontrol/base/struct.rb', line 9

def attributes
  @attributes
end

Class Method Details

+ (Object) from_soap(xml)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/icontrol/base/struct.rb', line 23

def from_soap(xml)
  aux = {}
  @attributes.each do |k,v|
    
    if v.respond_to?(:from_soap) # v.ancestors.find{ |i| i.name  =~ /^IControl/ }              
      aux[k] = v.from_soap(xml[k])
    else
      if v == Numeric
        aux[k] = xml[k].to_i
      else
        aux[k] = xml[k]
      end
    end
  end if xml
  return aux.values.compact.empty? ? nil : self.new(aux)
end

+ (Object) icontrol_attribute(attribute, klass, soap_attribute_name = nil)

When defining an struct we have to indicate every attribute type cause the soap responses are typed This method accepts three arguments:

attribute           = The name the atribute is going to be referenced in the instances (i.e. the ruby name)
klass               = The Ruby class of the attribute
soap_attribute_name = The soap name of the attribute in case it differs from the attribute name (DEPRECATED)


18
19
20
21
# File 'lib/icontrol/base/struct.rb', line 18

def icontrol_attribute(attribute,klass,soap_attribute_name = nil)
  @attributes ||= {}
  @attributes[attribute] = klass 
end

Instance Method Details

- (Object) to_soap

Converts to soap. In this case we fallback to the hash conversion of the attributes



43
44
45
# File 'lib/icontrol/base/struct.rb', line 43

def to_soap
  return @attributes
end