| 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 74
74: def normalize_attribute(name, value)
75: if name.nil?
76: raise RuntimeError, _('The first argument, name, must not be nil. ' \
77: 'Please report this as a bug!')
78: end
79:
80: name = normalize_attribute_name(name)
81: [name, schema.attribute(name).normalize_value(value)]
82: end
# File lib/active_ldap/attributes.rb, line 67
67: def normalize_attribute_name(name)
68: name.to_s.downcase
69: 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 116
116: def normalize_attribute_options(attr, value)
117: return [attr, value] unless attr.match(/;/)
118:
119: ret_attr, *options = attr.split(/;/)
120: [ret_attr,
121: [options.reverse.inject(value) {|result, option| {option => result}}]]
122: end
# File lib/active_ldap/attributes.rb, line 92
92: def unnormalize_attribute(name, values, result={})
93: if values.empty?
94: result[name] = []
95: else
96: values.each do |value|
97: if value.is_a?(Hash)
98: suffix, real_value = unnormalize_attribute_options(value)
99: new_name = name + suffix
100: result[new_name] ||= []
101: result[new_name].concat(real_value)
102: else
103: result[name] ||= []
104: result[name] << value.dup
105: end
106: end
107: end
108: result
109: 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 128
128: def unnormalize_attribute_options(value)
129: options = ''
130: ret_val = value
131: if value.class == Hash
132: options = ';' + value.keys[0]
133: ret_val = value[value.keys[0]]
134: if ret_val.class == Hash
135: sub_options, ret_val = unnormalize_attribute_options(ret_val)
136: options += sub_options
137: end
138: end
139: ret_val = [ret_val] unless ret_val.class == Array
140: [options, ret_val]
141: end