Class: ActiveLdap::Xml::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_ldap/xml.rb

Constant Summary

PRINTABLE_STRING =
/[\x20-\x7e\t\r\n]*/n

Instance Method Summary collapse

Constructor Details

#initialize(dn, attributes, schema, options = {}) ⇒ Serializer

Returns a new instance of Serializer



11
12
13
14
15
16
# File 'lib/active_ldap/xml.rb', line 11

def initialize(dn, attributes, schema, options={})
  @dn = dn
  @attributes = attributes
  @schema = schema
  @options = options
end

Instance Method Details

#to_sObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_ldap/xml.rb', line 18

def to_s
  root = @options[:root]
  indent = @options[:indent] || 2
  xml = @options[:builder] || Builder::XmlMarkup.new(:indent => indent)
  xml.tag!(root) do
    target_attributes.each do |key, values|
      values = normalize_values(values).sort_by {|value, _| value}
      if @schema.attribute(key).single_value?
        next if values.empty?
        serialize_attribute_value(xml, key, *values[0])
      else
        serialize_attribute_values(xml, key, values)
      end
    end
  end
end