Module: Softlayer::Generator::DataType
- Defined in:
- lib/softlayer/generator/data_type.rb
Constant Summary collapse
- @@document =
nil
- @@data_types =
nil
- @@all_elements =
nil
Class Method Summary collapse
- .add_parent_for(element) ⇒ Object
- .all_elements ⇒ Object
- .attributes_for(type) ⇒ Object
- .autoload_for(element) ⇒ Object
- .children_for(object) ⇒ Object
- .clean_data_types(objects) ⇒ Object
- .object_type(object) ⇒ Object
- .parent_for(object) ⇒ Object
- .parent_of(element) ⇒ Object
- .process_autoload(child) ⇒ Object
- .types ⇒ Object
- .valid_type?(type) ⇒ Boolean
Class Method Details
.add_parent_for(element) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# 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) ⇒ Object
84 85 86 87 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
77 78 79 80 81 82 |
# 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) ⇒ Object
89 90 91 92 93 94 95 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/softlayer/generator/data_type.rb', line 41 def parent_of(element) element.sub(/_[^\_]+\z/, '') end |
.process_autoload(child) ⇒ Object
109 110 111 112 |
# 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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Boolean
45 46 47 48 49 |
# 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 |