Module: ActiveLdap::Attributes::ClassMethods

Defined in:
lib/active_ldap/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attr_protected(*attributes) ⇒ Object



12
13
14
15
# File 'lib/active_ldap/attributes.rb', line 12

def attr_protected(*attributes)
  targets = attributes.collect {|attr| attr.to_s} - protected_attributes
  instance_variable_set("@attr_protected", targets)
end

#blank_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_ldap/attributes.rb', line 23

def blank_value?(value)
  case value
  when Hash
    value.values.all? {|val| blank_value?(val)}
  when Array
    value.all? {|val| blank_value?(val)}
  when String
    /\A\s*\z/ =~ value
  when nil
    true
  else
    value.blank?
  end
end

#protected_attributesObject



17
18
19
20
21
# File 'lib/active_ldap/attributes.rb', line 17

def protected_attributes
  ancestors[0..(ancestors.index(Base))].inject([]) do |result, ancestor|
    result + ancestor.instance_eval {@attr_protected ||= []}
  end
end

#remove_blank_value(value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/active_ldap/attributes.rb', line 38

def remove_blank_value(value)
  case value
  when Hash
    result = {}
    value.each do |k, v|
      v = remove_blank_value(v)
      next if v.nil?
      result[k] = v
    end
    result = nil if result.blank?
    result
  when Array
    result = []
    value.each do |v|
      v = remove_blank_value(v)
      next if v.nil?
      result << v
    end
    result = nil if result.blank?
    result
  when String
    if /\A\s*\z/ =~ value
      nil
    else
      value
    end
  else
    value
  end
end