Module: RForce

Included in:
Binding
Defined in:
lib/rforce.rb,
lib/rforce/version.rb,
lib/rforce/binding.rb,
lib/rforce/method_keys.rb,
lib/rforce/soap_response.rb,
lib/rforce/soap_pullable.rb,
lib/rforce/soap_response_rexml.rb,
lib/rforce/soap_response_expat.rb,
lib/rforce/soap_response_nokogiri.rb

Defined Under Namespace

Modules: MethodKeys, SoapPullable Classes: Binding, MethodHash, SoapResponseExpat, SoapResponseNokogiri, SoapResponseRexml

Constant Summary collapse

VERSION =
'0.12'
SoapResponse =

Use the fastest XML parser available.

(RForce::const_get(:SoapResponseNokogiri) rescue nil) ||
(RForce::const_get(:SoapResponseExpat) rescue nil)    ||
SoapResponseRexml

Instance Method Summary collapse

Instance Method Details

#expand(builder, args, xmlns = nil) ⇒ Object

Expand Ruby data structures into XML.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rforce.rb', line 54

def expand(builder, args, xmlns = nil)
  # Nest arrays: [:a, 1, :b, 2] => [[:a, 1], [:b, 2]]
  if args.is_a?(Array)
    args = args.each_slice(2).to_a
  end

  args.each do |key, value|
    attributes = xmlns ? {:xmlns => xmlns} : {}

    # If the XML tag requires attributes,
    # the tag name will contain a space
    # followed by a string representation
    # of a hash of attributes.
    #
    # e.g. 'sObject {"xsi:type" => "Opportunity"}'
    # becomes <sObject xsi:type="Opportunity>...</sObject>
    if key.is_a? String
      key, modifier = key.split(' ', 2)

      attributes.merge!(eval(modifier)) if modifier
    end

    # Create an XML element and fill it with this
    # value's sub-items.
    case value
    when Hash, Array then
      builder.tag!(key, attributes) do expand builder, value; end

    when String then
      builder.tag!(key, attributes) { builder.text! value }
    end
  end
end