module Softlayer::Generator::DataType
Public Class Methods
add_parent_for(element)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 32 def add_parent_for(element) return true if element == "SoftLayer" || element == "PortalLoginToken" || element == "McAfee" unless @@all_elements.include?(parent_of(element)) add_parent_for(parent_of(element)) @@all_elements << parent_of(element) end end
all_elements()
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 22 def all_elements load_data_file return @@all_elements if @@all_elements @@all_elements = types.dup @@all_elements.each do |element| add_parent_for(element) unless @@all_elements.include?(parent_of(element)) end end
attributes_for(type)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 61 def attributes_for(type) load_data_file type = 'SoftLayer_Network_Storage_Iscsi_OS_Type' if type == 'SoftLayer_Network_Storage_Iscsi_Os_Type' element = @@document.css("complexType[name=#{type}]") return [] if element.empty? # parse attributes attribs = {} element.first.css('sequence element').each do |attrib| name = attrib.attributes["name"].value type = attrib.attributes["type"].value attribs[name.underscore.to_sym] = Converter.type(type) end attribs end
autoload_for(element)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 97 def autoload_for(element) load_data_file children = all_elements.select { |x| x.match(/\A#{element}_[^\_]+\z/) } autoload = [] children.each do |child| class_symbol = child.sub(element+'_', '').to_sym class_file = process_autoload(child) autoload << [class_symbol, class_file] end autoload end
children_for(object)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 84 def children_for(object) load_data_file types.select { |x| x.match(/\A#{object}_[a-zA-Z]+\z/) } end
clean_data_types(objects)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 51 def clean_data_types(objects) objects.delete_if {|x| x.match(/ObjectFilter\z/) } objects.delete_if {|x| x.match(/ObjectMask\z/) } objects.delete_if {|x| x.match(/Array\z/) } %w{ authenticate resultLimit totalItems SoftLayer_Utility_ObjectFilter_Operation SoftLayer_Utility_ObjectFilter_Operation_Option SoftLayer_ObjectMask ArrayOfstring ArrayOfint ArrayOfunsignedInt json }.each do |filter| objects.delete(filter) end objects end
object_type(object)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 77 def object_type(object) load_data_file return :class if object == "SoftLayer_Network_Storage_Iscsi_Os_Type" return :class if types.include?(object) :module end
parent_for(object)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 89 def parent_for(object) load_data_file element = @@document.css("complexType[name=#{object}]") parent = element.css('complexContent extension').first return nil if parent.nil? parent.attributes["base"].value.sub('tns:', '') end
parent_of(element)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 41 def parent_of(element) element.sub(/_[^\_]+\z/, '') end
process_autoload(child)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 109 def process_autoload(child) return Converter.class_name(child).underscore if child =~ /Array\z/ Converter.type(child).underscore end
types()
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 9 def types load_data_file return @@data_types if @@data_types objects = [] @@document.css('complexType').each do |type| # next unless type.css('complexContent').empty? type_name = type.attributes["name"].value type_name = 'SoftLayer_Network_Storage_Iscsi_Os_Type' if type_name == 'SoftLayer_Network_Storage_Iscsi_OS_Type' objects << type_name end @@data_types = clean_data_types(objects) end
valid_type?(type)
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 45 def valid_type?(type) return false if type.match(/ObjectFilter\z/) return false if type.match(/Array\z/) true end
Private Class Methods
load_data_file()
click to toggle source
# File lib/softlayer/generator/data_type.rb, line 115 def load_data_file # @document = Wasabi.document File.read("data/types.xsd") return @@document if @@document @@document = Nokogiri::XML(File.read("data/types.xsd")) end
set_types(user_data_types)
click to toggle source
just to make tests faster
# File lib/softlayer/generator/data_type.rb, line 122 def set_types(user_data_types) @@data_types = user_data_types end