Module: Sequel::Plugins::XmlSerializer::DatasetMethods

Defined in:
lib/sequel/plugins/xml_serializer.rb

Instance Method Summary collapse

Instance Method Details

#to_xml(opts = OPTS) ⇒ Object

Return an XML string containing all model objects specified with this dataset. Takes all of the options available to Model#to_xml, as well as the :array_root_name option for specifying the name of the root node that contains the nodes for all of the instances.

Raises:



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/sequel/plugins/xml_serializer.rb', line 392

def to_xml(opts=OPTS)
  raise(Sequel::Error, "Dataset#to_xml") unless row_proc
  x = model.xml_builder(opts)
  name_proc = model.xml_serialize_name_proc(opts)
  array = if opts[:array]
    opts = opts.dup
    opts.delete(:array)
  else
    all
  end
  x.send(name_proc[opts.fetch(:array_root_name, model.send(:pluralize, model.send(:underscore, model.name))).to_s]) do |x1|
    array.each do |obj|
      obj.to_xml(opts.merge(:builder=>x1))
    end
  end
  x.to_xml
end