| Module | ActiveLdap::Attributes::Normalizable |
| In: |
lib/active_ldap/attributes.rb
|
Enforce typing: Hashes are for subtypes Arrays are for multiple entries
# File lib/active_ldap/attributes.rb, line 43
43: def normalize_attribute(name, value)
44: if name.nil?
45: raise RuntimeError, _('The first argument, name, must not be nil. ' \
46: 'Please report this as a bug!')
47: end
48:
49: name = normalize_attribute_name(name)
50: [name, schema.attribute(name).normalize_value(value)]
51: end
# File lib/active_ldap/attributes.rb, line 36
36: def normalize_attribute_name(name)
37: name.to_s.downcase
38: end
Makes the Hashized value from the full attribute name e.g. userCertificate;binary => "some_bin"
becomes userCertificate => {"binary" => "some_bin"}
# File lib/active_ldap/attributes.rb, line 85
85: def normalize_attribute_options(attr, value)
86: return [attr, value] unless attr.match(/;/)
87:
88: ret_attr, *options = attr.split(/;/)
89: [ret_attr,
90: [options.reverse.inject(value) {|result, option| {option => result}}]]
91: end
# File lib/active_ldap/attributes.rb, line 61
61: def unnormalize_attribute(name, values, result={})
62: if values.empty?
63: result[name] = []
64: else
65: values.each do |value|
66: if value.is_a?(Hash)
67: suffix, real_value = unnormalize_attribute_options(value)
68: new_name = name + suffix
69: result[new_name] ||= []
70: result[new_name].concat(real_value)
71: else
72: result[name] ||= []
73: result[name] << value.dup
74: end
75: end
76: end
77: result
78: end
Unnormalizes all of the subtypes from a given set of nested hashes and returns the attribute suffix and the final true value
# File lib/active_ldap/attributes.rb, line 97
97: def unnormalize_attribute_options(value)
98: options = ''
99: ret_val = value
100: if value.class == Hash
101: options = ';' + value.keys[0]
102: ret_val = value[value.keys[0]]
103: if ret_val.class == Hash
104: sub_options, ret_val = unnormalize_attribute_options(ret_val)
105: options += sub_options
106: end
107: end
108: ret_val = [ret_val] unless ret_val.class == Array
109: [options, ret_val]
110: end