Class: ROM::LDAP::Directory Abstract

Inherits:
Object
  • Object
show all
Includes:
Capabilities, Operations, Root, Tokenization, Transactions
Defined in:
lib/rom/ldap/directory.rb,
lib/rom/ldap/directory/env.rb,
lib/rom/ldap/directory/root.rb,
lib/rom/ldap/directory/entry.rb,
lib/rom/ldap/directory/password.rb,
lib/rom/ldap/directory/operations.rb,
lib/rom/ldap/directory/capabilities.rb,
lib/rom/ldap/directory/tokenization.rb,
lib/rom/ldap/directory/transactions.rb

Overview

This class is abstract.

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

Defined Under Namespace

Modules: Capabilities, Operations, Root, Tokenization, Transactions Classes: ENV, Entry, Password

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Transactions

#transaction

Methods included from Operations

#add, #base_total, #bind_as, #by_dn, #debug, #delete, #find, included, #modify, #query, #query_attributes

Methods included from Tokenization

included

Methods included from Capabilities

#bitwise?, #capabilities, #chainable?, #i18n?, #pageable?, #pruneable?, #sortable?

Methods included from Root

#contexts, #schema_attribute_types, #schema_object_classes, #sub_schema_entry, #supported_controls, #supported_extensions, #supported_features, #supported_mechanisms, #supported_versions, #type, #vendor, #vendor_name, #vendor_version

Constructor Details

#initialize(uri, options) ⇒ ROM::LDAP::Directory

Load vendor specific methods into the instance as singletons

See Also:



30
31
32
33
34
35
36
# 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

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



22
23
24
# File 'lib/rom/ldap/directory.rb', line 22

def env
  @env
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/rom/ldap/directory.rb', line 21

def logger
  @logger
end

Instance Method Details

#attribute_by(key, value) ⇒ Hash

Query parsed attribute definition hashes by key.

Examples:

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

Parameters:

  • key (Symbol)
  • value (Mixed)

Returns:

  • (Hash)


103
104
105
# 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_typesArray<Hash>

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

Returns:

  • (Array<Hash>)


75
76
77
# File 'lib/rom/ldap/directory.rb', line 75

def attribute_types
  @attribute_types ||= schema_attribute_types.map(&method(:to_attribute)).flatten.freeze
end

#baseString

Initial search base.

Returns:

  • (String)

    Defaults to empty string.



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

def base
  env.base
end

#canonical_attributes(attrs) ⇒ Array<String>

Look up canonical name for a formatted attribute.

Parameters:

  • attrs (Array<Symbol,String>)

    formatted attribute names.

Returns:

  • (Array<String>)

    camelCased canonical LDAP attributes.

See Also:

  • and Dataset#select


87
88
89
90
91
# 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

#clientClient

Encapsulates encoding and binding using socket.

Returns:



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

def client
  @client ||= Client.new(env.to_h)
end

#disconnectTrueClass

Expected method inside gateway.

Returns:

  • (TrueClass)


65
66
67
68
# File 'lib/rom/ldap/directory.rb', line 65

def disconnect
  client.close
  client.closed?
end

#inspectString

Returns:

  • (String)


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

def inspect
  "#<#{self.class} uri='#{env.connection}' vendor='#{vendor_name}' version='#{vendor_version}' />"
end

#key_mapHash

Hash of attribute names converted => original

Examples:

{ formatted_name: ‘canonicalName’ }


Returns:

  • (Hash)


113
114
115
# File 'lib/rom/ldap/directory.rb', line 113

def key_map
  attribute_types.map { |a| a.values_at(:name, :canonical) }.sort.to_h
end