Module: ActiveLdap::Attributes::Normalize
- Defined in:
- lib/active_ldap/attributes.rb
Instance Method Summary collapse
-
#normalize_attribute(name, value) ⇒ Object
Enforce typing: Hashes are for subtypes Arrays are for multiple entries.
- #normalize_attribute_name(name) ⇒ Object
- #unnormalize_attribute(name, values, result = {}) ⇒ Object
- #unnormalize_attributes(attributes) ⇒ Object
Instance Method Details
#normalize_attribute(name, value) ⇒ Object
Enforce typing: Hashes are for subtypes Arrays are for multiple entries
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_ldap/attributes.rb', line 32 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) rubyish_class_name = Inflector.underscore(value.class.name) handler = "normalize_attribute_value_of_#{rubyish_class_name}" if respond_to?(handler, true) [name, send(handler, name, value)] else [name, [value.to_s]] end end |
#normalize_attribute_name(name) ⇒ Object
25 26 27 |
# File 'lib/active_ldap/attributes.rb', line 25 def normalize_attribute_name(name) name.to_s.downcase end |
#unnormalize_attribute(name, values, result = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_ldap/attributes.rb', line 56 def unnormalize_attribute(name, values, result={}) if values.empty? result[name] = [] else values.each do |value| if value.is_a?(Hash) suffix, real_value = (value) new_name = name + suffix result[new_name] ||= [] result[new_name].concat(real_value) else result[name] ||= [] result[name] << value.dup end end end result end |
#unnormalize_attributes(attributes) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/active_ldap/attributes.rb', line 48 def unnormalize_attributes(attributes) result = {} attributes.each do |name, values| unnormalize_attribute(name, values, result) end result end |