Class: ROM::LDAP::Gateway Abstract

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/ldap/gateway.rb

Overview

This class is abstract.

Responsible for initialising connection, binding to server. Wrapping the connection in the directory and then dataset abstractions, and passing them to the relations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options) ⇒ LDAP::Gateway

Initialize an LDAP gateway

Gateways are typically initialized via ROM::Configuration object

Connects to a directory via options

Examples:

ROM.container(:ldap, uri, {})

Parameters:

  • uri (String)

    ‘ldap://127.0.0.1:389’ or nil

Options Hash (options):

  • :username (String)

    BINDDN Directory admin username.

  • :password (String)

    BINDDN Directory admin password.

  • :base (String)

    BASE Directory search base.

  • :timeout (Integer)

    Connection timeout in seconds.

  • :logger (Object)

    Defaults to $stdout



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rom/ldap/gateway.rb', line 51

def initialize(uri = nil, **options)
  @directory = Directory.new(uri, options)
  @logger = options.fetch(:logger) { ::Logger.new(STDOUT) }

  options.fetch(:extensions, EMPTY_ARRAY).each do |ext|
    next unless LDAP.available_extension?(ext)

    LDAP.load_extensions(ext)
  end

  super()
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



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

def directory
  @directory
end

#loggerObject (readonly)

Returns the value of attribute logger.



25
26
27
# File 'lib/rom/ldap/gateway.rb', line 25

def logger
  @logger
end

Instance Method Details

#[](filter) ⇒ Array<Directory::Entry> Also known as: call

Used by attribute_inferrer to query attributes.

Parameters:

  • filter (String)

Returns:



72
73
74
# File 'lib/rom/ldap/gateway.rb', line 72

def [](filter)
  directory.query_attributes(filter)
end

#attribute_typesArray<String>

Directory attributes identifiers and descriptions.

Returns:

  • (Array<String>)

See Also:



86
87
88
# File 'lib/rom/ldap/gateway.rb', line 86

def attribute_types
  directory.attribute_types
end

#dataset(name) ⇒ Dataset

An enumerable object for chainable queries.

Parameters:

  • name (String)

    An ldap compatible filter string. Used as the param to schema block in relation classes.

Returns:

  • (Dataset)

    Scoped by name filter.



111
112
113
# File 'lib/rom/ldap/gateway.rb', line 111

def dataset(name)
  Dataset.new(name: name, directory: directory)
end

#dataset?(name) ⇒ Boolean

Check for presence of entries under new filter.

Parameters:

  • name (String)

    An ldap compatible filter string.

Returns:

  • (Boolean)


98
99
100
# File 'lib/rom/ldap/gateway.rb', line 98

def dataset?(name)
  dataset(name).any?
end

#directory_typeSymbol

Underlying directory type

Returns:

  • (Symbol)


129
130
131
# File 'lib/rom/ldap/gateway.rb', line 129

def directory_type
  directory.type
end

#disconnect?

Disconnect from the server.

Returns:

  • (?)


139
140
141
# File 'lib/rom/ldap/gateway.rb', line 139

def disconnect
  directory.disconnect
end

#use_logger(logger) ⇒ Object

Parameters:

  • logger (Logger)


119
120
121
# File 'lib/rom/ldap/gateway.rb', line 119

def use_logger(logger)
  directory.logger = @logger = logger
end