lib/scaffold_parser/scaffolders/xsd/builder.rb in scaffold_parser-0.3.0 vs lib/scaffold_parser/scaffolders/xsd/builder.rb in scaffold_parser-0.4.0

- old
+ new

@@ -31,55 +31,54 @@ f.putsi " class #{node.to_class_name}" f.putsi " include BaseBuilder" f.puts f.putsi " def builder" - f.putsi " root = Ox::Element.new(element_name)" + f.putsi " root = Ox::Element.new(name)" + f.putsi " if data.respond_to? :attributes" + f.putsi " data.attributes.each { |k, v| root[k] = v }" + f.putsi " end" + f.puts if node.value_nodes.any? node.value_nodes.each do |node| - f.puts - f.putsi " if attributes.key? :#{node.to_name.underscore}" - f.putsi " element = Ox::Element.new('#{node.to_name}')" - f.putsi " element << attributes[:#{node.to_name.underscore}] if attributes[:#{node.to_name.underscore}]" - f.putsi " root << element" - f.putsi " end" + f.putsi " root << build_element('#{node.to_name}', data[:#{node.to_name.underscore}]) if data.key? :#{node.to_name.underscore}" end node.submodel_nodes.each do |node| f.puts - f.putsi " if attributes.key? :#{node.to_name.underscore}" - f.putsi " root << #{node.to_class_name}.new(attributes[:#{node.to_name.underscore}], '#{node.to_name}').builder" + f.putsi " if data.key? :#{node.to_name.underscore}" + f.putsi " root << #{node.to_class_name}.new('#{node.to_name}', data[:#{node.to_name.underscore}]).builder" f.putsi " end" end node.array_nodes.reject { |l| l.list_element.xs_type? }.each do |node| if node.named_list? f.puts - f.putsi " if attributes.key? :#{node.to_name.underscore}" + f.putsi " if data.key? :#{node.to_name.underscore}" f.putsi " element = Ox::Element.new('#{node.to_name}')" - f.putsi " attributes[:#{node.to_name.underscore}].each { |i| element << #{node.list_element.to_class_name}.new(i, '#{node.list_element.to_name}').builder }" + f.putsi " data[:#{node.to_name.underscore}].each { |i| element << #{node.list_element.to_class_name}.new('#{node.list_element.to_name}', i).builder }" f.putsi " root << element" f.putsi " end" else # simple_list f.puts - f.putsi " if attributes.key? :#{node.to_name.underscore}" - f.putsi " attributes[:#{node.to_name.underscore}].each { |i| root << #{node.list_element.to_class_name}.new(i, '#{node.list_element.to_name}').builder }" + f.putsi " if data.key? :#{node.to_name.underscore}" + f.putsi " data[:#{node.to_name.underscore}].each { |i| root << #{node.list_element.to_class_name}.new('#{node.list_element.to_name}', i).builder }" f.putsi " end" end end node.array_nodes.select { |l| l.list_element.xs_type? }.each do |node| f.puts if node.named_list? - f.putsi " if attributes.key? :#{node.to_name.underscore}" + f.putsi " if data.key? :#{node.to_name.underscore}" f.putsi " element = Ox::Element.new('#{node.to_name}')" - f.putsi " attributes[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.list_element.to_name}') << i }.each { |i| element << i }" + f.putsi " data[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.list_element.to_name}') << i }.each { |i| element << i }" f.putsi " root << element" f.putsi " end" else #simple_list - f.putsi " if attributes.key? :#{node.to_name.underscore}" - f.putsi " attributes[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.to_name}') << i }.each { |i| root << i }" + f.putsi " if data.key? :#{node.to_name.underscore}" + f.putsi " data[:#{node.to_name.underscore}].map { |i| Ox::Element.new('#{node.to_name}') << i }.each { |i| root << i }" f.putsi " end" end end f.puts