Module: ActiveLdap::Attributes::ClassMethods
- Defined in:
- lib/active_ldap/attributes.rb
Instance Method Summary collapse
- #attr_protected(*attributes) ⇒ Object
-
#normalize_attribute(name, value) ⇒ Object
Enforce typing: Hashes are for subtypes Arrays are for multiple entries.
- #normalize_attribute_name(name) ⇒ Object
- #protected_attributes ⇒ Object
- #unnormalize_attribute(name, values, result = {}) ⇒ Object
- #unnormalize_attributes(attributes) ⇒ Object
Instance Method Details
#attr_protected(*attributes) ⇒ Object
8 9 10 11 |
# File 'lib/active_ldap/attributes.rb', line 8 def attr_protected(*attributes) targets = attributes.collect {|attr| attr.to_s} - protected_attributes instance_variable_set("@attr_protected", targets) end |
#normalize_attribute(name, value) ⇒ Object
Enforce typing: Hashes are for subtypes Arrays are for multiple entries
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_ldap/attributes.rb', line 26 def normalize_attribute(name, value) logger.debug {"stub: called normalize_attribute" + "(#{name.inspect}, #{value.inspect})"} 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
19 20 21 |
# File 'lib/active_ldap/attributes.rb', line 19 def normalize_attribute_name(name) name.to_s.downcase end |
#protected_attributes ⇒ Object
13 14 15 16 17 |
# File 'lib/active_ldap/attributes.rb', line 13 def protected_attributes ancestors[0..(ancestors.index(Base))].inject([]) do |result, ancestor| result + ancestor.instance_eval {@attr_protected ||= []} end end |
#unnormalize_attribute(name, values, result = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_ldap/attributes.rb', line 52 def unnormalize_attribute(name, values, result={}) if values.empty? result[name] = [] else values.each do |value| if value.is_a?(Hash) suffix, real_value = extract_subtypes(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
44 45 46 47 48 49 50 |
# File 'lib/active_ldap/attributes.rb', line 44 def unnormalize_attributes(attributes) result = {} attributes.each do |name, values| unnormalize_attribute(name, values, result) end result end |