class Net::LDAP::Connection
def encode_sort_controls(sort_definitions)
:sort_control => ["givenname","sn"] #multiple strings or arrays
or
:sort_control => [["cn", "matchingRule", true]] #attribute, matchingRule, direction (true / false)
or
:sort_control => ["cn"] # just a string
The format of the sort control needs to be:
Allow the caller to specify a sort control
--
def encode_sort_controls(sort_definitions) return sort_definitions unless sort_definitions sort_control_values = sort_definitions.map do |control| control = Array(control) # if there is only an attribute name as a string then infer the orderinrule and reverseorder control[0] = String(control[0]).to_ber, control[1] = String(control[1]).to_ber, control[2] = (control[2] == true).to_ber control.to_ber_sequence end [ Net::LDAP::LDAPControls::SORT_REQUEST.to_ber, false.to_ber, sort_control_values.to_ber_sequence.to_s.to_ber, ].to_ber_sequence end