Module: WashOutHelper

Defined in:
app/helpers/wash_out_helper.rb

Instance Method Summary collapse

Instance Method Details

#wsdl_data(xml, params) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/wash_out_helper.rb', line 2

def wsdl_data(xml, params)
  params.each do |param|
    tag_name = param.name

    if !param.struct?
      if !param.multiplied
        xml.tag! tag_name, param.value, "xsi:type" => param.namespaced_type
      else
        param.value = [] unless param.value.is_a?(Array)
        param.value.each do |v|
          xml.tag! tag_name, v, "xsi:type" => param.namespaced_type
        end
      end
    else
      if !param.multiplied
        xml.tag! tag_name, "xsi:type" => param.namespaced_type do
          wsdl_data(xml, param.map)
        end
      else
        param.map.each do |p|
          xml.tag! tag_name, "xsi:type" => param.namespaced_type do
            wsdl_data(xml, p.map)
          end
        end
      end
    end
  end
end

#wsdl_occurence(param, inject, extend_with = {}) ⇒ Object



56
57
58
59
60
61
62
63
# File 'app/helpers/wash_out_helper.rb', line 56

def wsdl_occurence(param, inject, extend_with = {})
  data = !param.multiplied ? {} : {
    "#{'xsi:' if inject}minOccurs" => 0,
    "#{'xsi:' if inject}maxOccurs" => 'unbounded'
  }

  extend_with.merge(data)
end

#wsdl_type(xml, param, defined = []) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/wash_out_helper.rb', line 31

def wsdl_type(xml, param, defined=[])
  more = []

  if param.struct?
    if !defined.include?(param.basic_type)
      xml.tag! "xsd:complexType", :name => param.basic_type do
        xml.tag! "xsd:sequence" do
          param.map.each do |value|
            more << value if value.struct?
            xml.tag! "xsd:element", wsdl_occurence(value, false, :name => value.name, :type => value.namespaced_type)
          end
        end
      end

      defined << param.basic_type
    elsif !param.classified?
      raise RuntimeError, "Duplicate use of `#{param.basic_type}` type name. Consider using classified types."
    end
  end

  more.each do |p|
    wsdl_type xml, p, defined
  end
end