### Home Classes Methods

### In Files

- lib/active_ldap/xml.rb

### Parent

Object

### Methods

- ::new
- #normalize_value
- #normalize_values
- #serialize_attribute_value
- #serialize_attribute_values
- #target_attributes
- #to_s

### Files

- USAGE

### Class/Module Index

Quicksearch

- ActiveLdap
- ActiveLdap::ActionController
- ActiveLdap::ActionController::LdapBenchmarking
- ActiveLdap::Acts
- ActiveLdap::Acts::Tree
- ActiveLdap::Acts::Tree::ClassMethods
- ActiveLdap::Adapter
- ActiveLdap::Adapter::Base
- ActiveLdap::Adapter::Jndi
- ActiveLdap::Adapter::JndiConnection
- ActiveLdap::Adapter::JndiConnection::ModifyRecord
- ActiveLdap::Adapter::JndiConnection::Scope
- ActiveLdap::Adapter::Ldap
- ActiveLdap::Adapter::Ldap::Method
- ActiveLdap::Adapter::Ldap::Method::Base
- ActiveLdap::Adapter::Ldap::Method::Plain
- ActiveLdap::Adapter::Ldap::Method::SSL
- ActiveLdap::Adapter::Ldap::Method::TLS
- ActiveLdap::Adapter::NetLdap
- ActiveLdap::Association
- ActiveLdap::Association::BelongsTo
- ActiveLdap::Association::BelongsToMany
- ActiveLdap::Association::Children
- ActiveLdap::Association::Collection
- ActiveLdap::Association::HasMany
- ActiveLdap::Association::HasManyUtils
- ActiveLdap::Association::HasManyWrap
- ActiveLdap::Association::Proxy
- ActiveLdap::Associations
- ActiveLdap::Associations::ClassMethods
- ActiveLdap::AttributeMethods
- ActiveLdap::AttributeMethods::BeforeTypeCast
- ActiveLdap::AttributeMethods::Dirty
- ActiveLdap::AttributeMethods::Query
- ActiveLdap::AttributeMethods::Read
- ActiveLdap::AttributeMethods::Write
- ActiveLdap::Attributes
- ActiveLdap::Attributes::ClassMethods
- ActiveLdap::Attributes::Normalizable
- ActiveLdap::Callbacks
- ActiveLdap::Callbacks::ClassMethods
- ActiveLdap::Command
- ActiveLdap::Compatible
- ActiveLdap::Configuration
- ActiveLdap::Configuration::ClassMethods
- ActiveLdap::Connection
- ActiveLdap::Connection::ClassMethods
- ActiveLdap::DN
- ActiveLdap::DistinguishedName
- ActiveLdap::DistinguishedName::Parser
- ActiveLdap::Entry
- ActiveLdap::EntryAttribute
- ActiveLdap::Escape
- ActiveLdap::Generators
- ActiveLdap::Generators::ModelGenerator
- ActiveLdap::Generators::ScaffoldGenerator
- ActiveLdap::GetText
- ActiveLdap::GetText::Parser
- ActiveLdap::GetTextSupport
- ActiveLdap::Helper
- ActiveLdap::HumanReadable
- ActiveLdap::HumanReadable::ClassMethods
- ActiveLdap::LDIF
- ActiveLdap::LdapError
- ActiveLdap::Ldif
- ActiveLdap::Ldif::AddRecord
- ActiveLdap::Ldif::Attribute
- ActiveLdap::Ldif::Attributes
- ActiveLdap::Ldif::ChangeRecord
- ActiveLdap::Ldif::ChangeRecord::Control
- ActiveLdap::Ldif::ContentRecord
- ActiveLdap::Ldif::DeleteRecord
- ActiveLdap::Ldif::ModifyDNRecord
- ActiveLdap::Ldif::ModifyNameRecord
- ActiveLdap::Ldif::ModifyRDNRecord
- ActiveLdap::Ldif::ModifyRecord
- ActiveLdap::Ldif::ModifyRecord::AddOperation
- ActiveLdap::Ldif::ModifyRecord::DeleteOperation
- ActiveLdap::Ldif::ModifyRecord::Operation
- ActiveLdap::Ldif::ModifyRecord::ReplaceOperation
- ActiveLdap::Ldif::Parser
- ActiveLdap::Ldif::Record
- ActiveLdap::Ldif::Scanner
- ActiveLdap::LogSubscriber
- ActiveLdap::ObjectClass
- ActiveLdap::ObjectClass::ClassMethods
- ActiveLdap::Operations
- ActiveLdap::Operations::ClassOnlyDelete
- ActiveLdap::Operations::ClassOnlyUpdate
- ActiveLdap::Operations::Common
- ActiveLdap::Operations::Delete
- ActiveLdap::Operations::Find
- ActiveLdap::Operations::LDIF
- ActiveLdap::Operations::LDIF::AddRecordLoadable
- ActiveLdap::Operations::LDIF::ContentRecordLoadable
- ActiveLdap::Operations::LDIF::DeleteRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyNameRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::AddOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::DeleteOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::ReplaceOperationModifiable
- ActiveLdap::Operations::Update
- ActiveLdap::Persistence
- ActiveLdap::Populate
- ActiveLdap::Railtie
- ActiveLdap::Railties
- ActiveLdap::Railties::ControllerRuntime
- ActiveLdap::Railties::ControllerRuntime::ClassMethods
- ActiveLdap::Schema
- ActiveLdap::Schema::Attribute
- ActiveLdap::Schema::Entry
- ActiveLdap::Schema::ObjectClass
- ActiveLdap::Schema::Syntax
- ActiveLdap::Schema::Syntaxes
- ActiveLdap::Schema::Syntaxes::Base
- ActiveLdap::Schema::Syntaxes::BitString
- ActiveLdap::Schema::Syntaxes::Boolean
- ActiveLdap::Schema::Syntaxes::CountryString
- ActiveLdap::Schema::Syntaxes::DirectoryString
- ActiveLdap::Schema::Syntaxes::DistinguishedName
- ActiveLdap::Schema::Syntaxes::GeneralizedTime
- ActiveLdap::Schema::Syntaxes::Integer
- ActiveLdap::Schema::Syntaxes::JPEG
- ActiveLdap::Schema::Syntaxes::NameAndOptionalUID
- ActiveLdap::Schema::Syntaxes::NumericString
- ActiveLdap::Schema::Syntaxes::OID
- ActiveLdap::Schema::Syntaxes::ObjectSecurityDescriptor
- ActiveLdap::Schema::Syntaxes::OctetString
- ActiveLdap::Schema::Syntaxes::OtherMailbox
- ActiveLdap::Schema::Syntaxes::PostalAddress
- ActiveLdap::Schema::Syntaxes::PrintableString
- ActiveLdap::Schema::Syntaxes::TelephoneNumber
- ActiveLdap::UserPassword
- ActiveLdap::UserPassword::Salt
- ActiveLdap::Validations
- ActiveLdap::XML
- ActiveLdap::Xml
- ActiveLdap::Xml::Serializer
- LDAP
- LDAP::Conn
- LDAP::Mod
- Net
- Net::LDAP
- Net::LDAP::Entry
- ActionView
- ActionView::Base
- URI
- URI::LDAPS
- Object
- Timeout

No matching classes.

# 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
    def initialize(dn, attributes, schema, options={})
      @dn = dn
      @attributes = attributes
      @schema = schema
      @options = options
    end

### Public Instance Methods

to_s() click to toggle source

    # 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

### Private Instance Methods

normalize_value(value, options=[]) click to toggle source

    # File lib/active_ldap/xml.rb, line 75
    def normalize_value(value, options=[])
      targets = []
      case value
      when Hash
        value.each do |real_option, real_value|
          targets.concat(normalize_value(real_value, options + [real_option]))
        end
      when Array
        value.each do |real_value|
          targets.concat(normalize_value(real_value, options))
        end
      when DN
        targets.concat(normalize_value(value.to_s, options))
      when nil
        # ignore
      else
        if /\A#{PRINTABLE_STRING}\z/ !~ value
          value = [value].pack("m").gsub(/\n/, '')
          options += ["base64"]
        end
        xml_attributes = {}
        options.each do |name, val|
          xml_attributes[name] = val || "true"
        end
        targets << [value, xml_attributes]
      end
      targets
    end

normalize_values(values) click to toggle source

    # File lib/active_ldap/xml.rb, line 67
    def normalize_values(values)
      targets = []
      values.each do |value|
        targets.concat(normalize_value(value))
      end
      targets
    end

serialize_attribute_value(xml, name, value, xml_attributes) click to toggle source

    # File lib/active_ldap/xml.rb, line 122
    def serialize_attribute_value(xml, name, value, xml_attributes)
      xml.tag!(name, value, xml_attributes)
    end

serialize_attribute_values(xml, name, values) click to toggle source

    # File lib/active_ldap/xml.rb, line 104
    def serialize_attribute_values(xml, name, values)
      return if values.blank?

      if name == "dn" or @options[:type].to_s.downcase == "ldif"
        values.each do |value, xml_attributes|
          serialize_attribute_value(xml, name, value, xml_attributes)
        end
      else
        plural_name = name.pluralize
        attributes = @options[:skip_types] ? {} : {"type" => "array"}
        xml.tag!(plural_name, attributes) do
          values.each do |value, xml_attributes|
            serialize_attribute_value(xml, name, value, xml_attributes)
          end
        end
      end
    end

target_attributes() click to toggle source

    # File lib/active_ldap/xml.rb, line 36
    def target_attributes
      except_dn = false
      only = @options[:only] || []
      except = @options[:except] || []
      if !only.empty?
        attributes = []
        except_dn = true
        only.each do |name|
          if name == "dn"
            except_dn = false
          elsif @attributes.has_key?(name)
            attributes << [name, @attributes[name]]
          end
        end
      elsif !except.empty?
        attributes = @attributes.dup
        except.each do |name|
          if name == "dn"
            except_dn = true
          else
            attributes.delete(name)
          end
        end
      else
        attributes = @attributes.dup
      end
      attributes = attributes.sort_by {|key, values| key}
      attributes.unshift(["dn", [@dn]]) unless except_dn
      attributes
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.