Class: ROM::LDAP::Directory::Entry
- Inherits:
-
Object
- Object
- ROM::LDAP::Directory::Entry
- 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.
Instance Attribute Summary collapse
- #attributes ⇒ Array<Array> readonly private
-
#dn ⇒ String
readonly
Distinguished Name.
Instance Method Summary collapse
-
#each_value(key, &block) ⇒ Object
Iterate over the values of a given attribute.
-
#fetch(key) ⇒ Array<String>
(also: #[])
Retrieve values for a given attribute.
-
#first(key) ⇒ String
Find the first (only) value for an attribute.
-
#include?(tuple) ⇒ Boolean
Mostly used by the test suite.
- #inspect ⇒ String
-
#method_missing(meth, *args, &block) ⇒ Object
Defer to enumerable hash methods before entry values.
-
#slice(*keys) ⇒ Hash
Compatibility method with Ruby < 2.5.
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
#attributes ⇒ Array<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.
47 |
# File 'lib/rom/ldap/directory/entry.rb', line 47 param :attributes, type: Types::Strict::Array, reader: :private |
#dn ⇒ String (readonly)
Returns 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.
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.
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.
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.
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 |
#inspect ⇒ 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
109 110 111 |
# File 'lib/rom/ldap/directory/entry.rb', line 109 def slice(*keys) formatted.select { |k, _v| keys.include?(k) } end |