Module: DataMapper::Serialize

Defined in:
lib/dm-serializer/common.rb,
lib/dm-serializer/to_xml.rb,
lib/dm-serializer/xml_serializers.rb,
lib/dm-serializer/xml_serializers/rexml.rb,
lib/dm-serializer/xml_serializers/libxml.rb,
lib/dm-serializer/xml_serializers/nokogiri.rb

Defined Under Namespace

Modules: XMLSerializers Classes: Support

Instance Method Summary collapse

Instance Method Details

#properties_to_serialize(options) ⇒ Array

Returns propreties to serialize based on :only or :exclude arrays, if provided :only takes precendence over :exclude

Returns:

  • (Array)

    properties that need to be serialized



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dm-serializer/common.rb', line 7

def properties_to_serialize(options)
  only_properties     = Array(options[:only])
  excluded_properties = Array(options[:exclude])

  model.properties(repository.name).reject do |p|
    if only_properties.include? p.name
      false
    else
      excluded_properties.include?(p.name) || !(only_properties.empty? || only_properties.include?(p.name))
    end
  end
end

#to_xml(opts = {}) ⇒ REXML::Document

Serialize a Resource to XML

Returns:

  • (REXML::Document)

    an XML representation of this Resource



10
11
12
13
# File 'lib/dm-serializer/to_xml.rb', line 10

def to_xml(opts = {})
  xml = XMLSerializers::SERIALIZER
  xml.output(to_xml_document(opts)).to_s
end