Class: LDAP::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dn, attributes) ⇒ Entry

Returns a new instance of Entry.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ldap/entry.rb', line 22

def initialize(dn, attributes)
  @dn = dn
  @attributes = attributes
  @keys = @attributes.keys
  @attributes = @keys.inject({}) do |hash, key|
    if @attributes[key].any?{|v| !v.is_a?(String)}
      @attributes[key] = @attributes[key].map do |val|
        val.is_a?(String) ? val : String.from_java_bytes(val)
      end
    end
    hash[key.downcase] = @attributes[key]
    hash
  end
end

Class Method Details

.create_from_search_result(search_result) ⇒ Object



16
17
18
19
# File 'lib/ldap/entry.rb', line 16

def create_from_search_result(search_result)
  new(search_result.name_in_namespace, (search_result.attributes.get_all.inject({}){|hash, attr| 
                                          hash[attr.getID()] = attr.getAll.to_a; hash}))
end

Instance Method Details

#get_attributesObject Also known as: attrs



37
38
39
# File 'lib/ldap/entry.rb', line 37

def get_attributes
  @keys
end

#get_dnObject Also known as: dn



43
44
45
# File 'lib/ldap/entry.rb', line 43

def get_dn
  @dn
end

#get_values(attr) ⇒ Object Also known as: vals, []



49
50
51
# File 'lib/ldap/entry.rb', line 49

def get_values(attr)
  @attributes[attr.downcase]
end

#hashObject



60
61
62
# File 'lib/ldap/entry.rb', line 60

def hash
  @attributes.hash + @dn.hash
end

#inspectObject



56
57
58
# File 'lib/ldap/entry.rb', line 56

def inspect
  super.split(' ').first + "\n#{(@keys.inject({}){|hash, name| hash[name] = @attributes[name.downcase];hash}.update('dn'=>[@dn])).inspect}>"
end