Class: ROM::LDAP::Directory::Entry

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::Cache, Initializer
Includes:
Memoizable
Defined in:
lib/rom/ldap/directory/entry.rb

Overview

A Hash-like object wrapping the DN and attributes returned by the server. Contains the canonical attributes hash and a formatted version. BER format converted to primitive String ensures clean output in #to_yaml. Accessed when iterating over dataset during #modify and #delete. Exposes methods #fetch, #first, #each_value and #include?. All other method calls are forwarded to the formatted tuple.

See Also:

  • Directory#query

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

Defer to enumerable hash methods before entry values.



115
116
117
# File 'lib/rom/ldap/directory/entry.rb', line 115

def method_missing(meth, *args, &block)
  formatted.send(meth, *args, &block) if formatted.respond_to?(meth) || super
end

Instance Attribute Details

#attributesArray<Array> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Array>)


47
# File 'lib/rom/ldap/directory/entry.rb', line 47

param :attributes, type: Types::Strict::Array, reader: :private

#dnString (readonly)

Returns Distinguished Name.

Returns:

  • (String)

    Distinguished Name



41
# File 'lib/rom/ldap/directory/entry.rb', line 41

param :dn, proc(&:to_s), type: Types::Strict::String

Instance Method Details

#each_value(key, &block) ⇒ Object

Iterate over the values of a given attribute.

Examples:


entry.each_value(:object_class, &:to_sym)
entry.each_value(:object_class) { |o| o.to_sym }

Parameters:

  • key (Symbol)

    canonical attribute name



83
84
85
# File 'lib/rom/ldap/directory/entry.rb', line 83

def each_value(key, &block)
  fetch(key).map(&block)
end

#fetch(key) ⇒ Array<String> Also known as: []

Retrieve values for a given attribute.

Parameters:

  • key (String, Symbol)

Returns:

  • (Array<String>)

See Also:



57
58
59
# File 'lib/rom/ldap/directory/entry.rb', line 57

def fetch(key)
  formatted.fetch(rename(key), canonical[key])
end

#first(key) ⇒ String

Find the first (only) value for an attribute.

Parameters:

  • key (Symbol, String)

    Attribute name.

Returns:

  • (String)

See Also:



70
71
72
# File 'lib/rom/ldap/directory/entry.rb', line 70

def first(key)
  fetch(key)&.first
end

#include?(tuple) ⇒ Boolean

Mostly used by the test suite.

Examples:


expect(relation.first).to include(attr: %w[val1 val2])

Parameters:

  • tuple (Hash)

    keys and array of values

Returns:

  • (Boolean)


97
98
99
100
101
# File 'lib/rom/ldap/directory/entry.rb', line 97

def include?(tuple)
  tuple.flat_map { |attr, vals| vals.map { |v| fetch(attr).include?(v) } }.all?
rescue NoMethodError
  false
end

#inspectString

Returns:

  • (String)


121
122
123
# File 'lib/rom/ldap/directory/entry.rb', line 121

def inspect
  %(#<#{self.class} #{dn.empty? ? 'rootDSE' : dn} />)
end

#slice(*keys) ⇒ Hash

Compatibility method with Ruby < 2.5

Returns:

  • (Hash)

See Also:



109
110
111
# File 'lib/rom/ldap/directory/entry.rb', line 109

def slice(*keys)
  formatted.select { |k, _v| keys.include?(k) }
end