module ActiveLdap::Attributes::Normalizable
def normalize_attribute(name, value)
Hashes are for subtypes
Enforce typing:
def normalize_attribute(name, value) if name.nil? raise RuntimeError, _('The first argument, name, must not be nil. ' \ 'Please report this as a bug!') end name = normalize_attribute_name(name) [name, schema.attribute(name).normalize_value(value)] end
def normalize_attribute_name(name)
def normalize_attribute_name(name) name.to_s.downcase end
def normalize_attribute_options(attr, value)
e.g. userCertificate;binary => "some_bin"
Makes the Hashized value from the full attribute name
normalize_attribute_options
def normalize_attribute_options(attr, value) return [attr, value] unless attr.match(/;/) ret_attr, *options = attr.split(/;/) [ret_attr, [options.reverse.inject(value) {|result, option| {option => result}}]] end
def unnormalize_attribute(name, values, result={})
def unnormalize_attribute(name, values, result={}) if values.empty? result[name] = [] else values.each do |value| if value.is_a?(Hash) suffix, real_value = unnormalize_attribute_options(value) new_name = name + suffix unnormalize_attribute(new_name, real_value, result) else result[name] ||= [] if value.is_a?(DN) result[name] << value.to_s else result[name] << value.dup end end end end result end
def unnormalize_attribute_options(value)
Unnormalizes all of the subtypes from a given set of nested hashes
unnormalize_attribute_options
def unnormalize_attribute_options(value) options = '' ret_val = value if value.class == Hash options = ';' + value.keys[0] ret_val = value[value.keys[0]] if ret_val.class == Hash sub_options, ret_val = unnormalize_attribute_options(ret_val) options += sub_options end end ret_val = [ret_val] unless ret_val.class == Array [options, ret_val] end
def unnormalize_attributes(attributes)
def unnormalize_attributes(attributes) result = {} attributes.each do |name, values| unnormalize_attribute(name, values, result) end result end