Class ActiveLdap::Xml::Serializer
In: lib/active_ldap/xml.rb
Parent: Object
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid DistinguishedNameNotSetError EntryNotFound LdapError SaveError StrongAuthenticationRequired NotImplemented AdapterNotFound TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError ConnectionNotSetup DistinguishedNameInvalid Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] Base DistinguishedName Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Normalizable Common Find LDIF Delete Update ActiveRecord::Callbacks GetText Parser Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport ActiveRecord::Validations Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/xml.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb Compatible ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command ClassMethods Normalizable Attributes Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Configuration ClassMethods ObjectClass ClassMethods Callbacks lib/active_ldap/get_text/parser.rb GetText lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb lib/active_ldap/adapter/jndi.rb Adapter Validations GetTextFallback Helper ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_46_0.png

Methods

Constants

PRINTABLE_STRING = /[\x20-\x7e\w\s]*/

Public Class methods

[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

[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

[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/u, '')
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

[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

[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

[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

[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

[Validate]