Parent

Class Index [+]

Quicksearch

ActiveLdap::Xml::Serializer

Constants

PRINTABLE_STRING

Public Class Methods

new(dn, attributes, schema, options={}) click to toggle source
    # File lib/active_ldap/xml.rb, line 11
11:       def initialize(dn, attributes, schema, options={})
12:         @dn = dn
13:         @attributes = attributes
14:         @schema = schema
15:         @options = options
16:       end

Public Instance Methods

to_s() click to toggle source
    # File lib/active_ldap/xml.rb, line 18
18:       def to_s
19:         root = @options[:root]
20:         indent = @options[:indent] || 2
21:         xml = @options[:builder] || Builder::XmlMarkup.new(:indent => indent)
22:         xml.tag!(root) do
23:           target_attributes.each do |key, values|
24:             values = normalize_values(values).sort_by {|value, _| value}
25:             if @schema.attribute(key).single_value?
26:               serialize_attribute_value(xml, key, *values[0])
27:             else
28:               serialize_attribute_values(xml, key, values)
29:             end
30:           end
31:         end
32:       end

Private Instance Methods

normalize_value(value, options=[]) click to toggle source
    # File lib/active_ldap/xml.rb, line 58
58:       def normalize_value(value, options=[])
59:         targets = []
60:         case value
61:         when Hash
62:           value.each do |real_option, real_value|
63:             targets.concat(normalize_value(real_value, options + [real_option]))
64:           end
65:         when Array
66:           value.each do |real_value|
67:             targets.concat(normalize_value(real_value, options))
68:           end
69:         when DN
70:           targets.concat(normalize_value(value.to_s, options))
71:         when nil
72:           # ignore
73:         else
74:           if /\A#{PRINTABLE_STRING}\z/ !~ value
75:             value = [value].pack("m").gsub(/\n/, '')
76:             options += ["base64"]
77:           end
78:           xml_attributes = {}
79:           options.each do |name, val|
80:             xml_attributes[name] = val || "true"
81:           end
82:           targets << [value, xml_attributes]
83:         end
84:         targets
85:       end
normalize_values(values) click to toggle source
    # File lib/active_ldap/xml.rb, line 50
50:       def normalize_values(values)
51:         targets = []
52:         values.each do |value|
53:           targets.concat(normalize_value(value))
54:         end
55:         targets
56:       end
serialize_attribute_value(xml, name, value, xml_attributes) click to toggle source
     # File lib/active_ldap/xml.rb, line 105
105:       def serialize_attribute_value(xml, name, value, xml_attributes)
106:         xml.tag!(name, value, xml_attributes)
107:       end
serialize_attribute_values(xml, name, values) click to toggle source
     # File lib/active_ldap/xml.rb, line 87
 87:       def serialize_attribute_values(xml, name, values)
 88:         return if values.blank?
 89: 
 90:         if name == "dn" or @options[:type].to_s.downcase == "ldif"
 91:           values.each do |value, xml_attributes|
 92:             serialize_attribute_value(xml, name, value, xml_attributes)
 93:           end
 94:         else
 95:           plural_name = name.pluralize
 96:           attributes = @options[:skip_types] ? {} : {"type" => "array"}
 97:           xml.tag!(plural_name, attributes) do
 98:             values.each do |value, xml_attributes|
 99:               serialize_attribute_value(xml, name, value, xml_attributes)
100:             end
101:           end
102:         end
103:       end
target_attributes() click to toggle source
    # File lib/active_ldap/xml.rb, line 35
35:       def target_attributes
36:         except_dn = false
37:         attributes = @attributes.dup
38:         (@options[:except] || []).each do |name|
39:           if name == "dn"
40:             except_dn = true
41:           else
42:             attributes.delete(name)
43:           end
44:         end
45:         attributes = attributes.sort_by {|key, values| key}
46:         attributes.unshift(["dn", [@dn]]) unless except_dn
47:         attributes
48:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.