| 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 78
78: def normalize_attribute(name, value)
79: if name.nil?
80: raise RuntimeError, _('The first argument, name, must not be nil. ' \
81: 'Please report this as a bug!')
82: end
83:
84: name = normalize_attribute_name(name)
85: [name, schema.attribute(name).normalize_value(value)]
86: end
# File lib/active_ldap/attributes.rb, line 71
71: def normalize_attribute_name(name)
72: name.to_s.downcase
73: 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 123
123: def normalize_attribute_options(attr, value)
124: return [attr, value] unless attr.match(/;/)
125:
126: ret_attr, *options = attr.split(/;/)
127: [ret_attr,
128: [options.reverse.inject(value) {|result, option| {option => result}}]]
129: end
# File lib/active_ldap/attributes.rb, line 96
96: def unnormalize_attribute(name, values, result={})
97: if values.empty?
98: result[name] = []
99: else
100: values.each do |value|
101: if value.is_a?(Hash)
102: suffix, real_value = unnormalize_attribute_options(value)
103: new_name = name + suffix
104: unnormalize_attribute(new_name, real_value, result)
105: else
106: result[name] ||= []
107: if value.is_a?(DN)
108: result[name] << value.to_s
109: else
110: result[name] << value.dup
111: end
112: end
113: end
114: end
115: result
116: 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 135
135: def unnormalize_attribute_options(value)
136: options = ''
137: ret_val = value
138: if value.class == Hash
139: options = ';' + value.keys[0]
140: ret_val = value[value.keys[0]]
141: if ret_val.class == Hash
142: sub_options, ret_val = unnormalize_attribute_options(ret_val)
143: options += sub_options
144: end
145: end
146: ret_val = [ret_val] unless ret_val.class == Array
147: [options, ret_val]
148: end