class ROM::LDAP::Directory

@abstract

Builds LDAP directory abstraction over TCP connection instance.
Includes vendor specific modules once initialised.

Attributes

env[R]
logger[RW]

Public Class Methods

new(uri, options) click to toggle source

Load vendor specific methods into the instance as singletons

@see Gateway#directory

@return [ROM::LDAP::Directory]

# File lib/rom/ldap/directory.rb, line 30
def initialize(uri, options)
  @env    = ENV.new(uri, options)
  @logger = options.fetch(:logger, Logger.new($stdout))

  require "rom/ldap/directory/vendors/#{type}"
  extend LDAP.const_get(Inflector.camelize(type))
end

Public Instance Methods

attribute_by(key, value) click to toggle source

Query parsed attribute definition hashes by key.

@example

directory.attribute_by(:name, :jpeg_photo) => { name: :jpeg_photo, ...}

@param key [Symbol] @param value [Mixed]

@return [Hash]

# File lib/rom/ldap/directory.rb, line 103
def attribute_by(key, value)
  attribute_types.find { |a| a[key].eql?(value) } || EMPTY_HASH
end
attribute_types() click to toggle source

Parsed attributes. Output influenced by LDAP.formatter. Ordered alphabetically.

@return [Array<Hash>]

# File lib/rom/ldap/directory.rb, line 75
def attribute_types
  @attribute_types ||= schema_attribute_types.map(&method(:to_attribute)).flatten.freeze
end
base() click to toggle source

Initial search base.

@return [String] Defaults to empty string.

@api public

# File lib/rom/ldap/directory.rb, line 49
def base
  env.base
end
canonical_attributes(attrs) click to toggle source

Look up canonical name for a formatted attribute.

@see Dataset#order_by and Dataset#select

@param attrs [Array<Symbol,String>] formatted attribute names.

@return [Array<String>] camelCased canonical LDAP attributes.

# File lib/rom/ldap/directory.rb, line 87
def canonical_attributes(attrs)
  attrs.map do |formatted|
    attribute_by(:name, formatted).fetch(:canonical, formatted.to_s)
  end
end
client() click to toggle source

Encapsulates encoding and binding using socket.

@return [Client]

# File lib/rom/ldap/directory.rb, line 57
def client
  @client ||= Client.new(**env.to_h)
end
disconnect() click to toggle source

Expected method inside gateway.

@return [TrueClass]

# File lib/rom/ldap/directory.rb, line 65
def disconnect
  client.close
  client.closed?
end
inspect() click to toggle source

@return [String]

@api public

# File lib/rom/ldap/directory.rb, line 120
def inspect
  "#<#{self.class} uri='#{env.connection}' vendor='#{vendor_name}' version='#{vendor_version}' />"
end
key_map() click to toggle source

Hash of attribute names converted => original

@example { formatted_name: 'canonicalName' }

@return [Hash]

# File lib/rom/ldap/directory.rb, line 113
def key_map
  attribute_types.map { |a| a.values_at(:name, :canonical) }.sort.to_h
end