class ASF::Base

Superclass for all classes which are backed by LDAP data. Encapsulates the management of collections to weak references to instance data, for both performance and funcational reasons. Sequentially finding the same same object will return the same instance unless the prior instance has been reclaimed by garbage collection. This often prevents large numbers of requests to fetch the same data from LDAP.

This class also contains a number of helper classes that will construct various LDAP mod objects.

Attributes

name[R]

Simple name for the LDAP object, generally the value of uid for people, and the value of cn for all of the rest.

Public Class Methods

[](name) click to toggle source

Find an instance of this class, given a name

# File lib/whimsy/asf/ldap.rb, line 441
def self.[] name
  new(name)
end
base() click to toggle source

return the LDAP base for this object: identifies the subtree where this object can be found.

# File lib/whimsy/asf/ldap.rb, line 424
def self.base
  @base
end
collection() click to toggle source

return the collection of instances of this class, as a hash. Note the values are weak references, so may have already been reclaimed.

# File lib/whimsy/asf/ldap.rb, line 436
def self.collection
  @collection ||= Hash.new
end
find(name) click to toggle source

Find an instance of this class, given a name

# File lib/whimsy/asf/ldap.rb, line 446
def self.find name
  new(name)
end
mod_add(attr, vals) click to toggle source

helper method to construct LDAP_MOD_ADD objects

# File lib/whimsy/asf/ldap.rb, line 489
def self.mod_add(attr, vals)
  ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, attr.to_s, Array(vals))
end
mod_delete(attr, vals) click to toggle source

helper method to construct LDAP_MOD_DELETE objects

# File lib/whimsy/asf/ldap.rb, line 500
def self.mod_delete(attr, vals)
  ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, attr.to_s, Array(vals))
end
mod_replace(attr, vals) click to toggle source

helper method to construct LDAP_MOD_REPLACE objects

# File lib/whimsy/asf/ldap.rb, line 494
def self.mod_replace(attr, vals)
  vals = Array(vals) unless Hash === vals
  ::LDAP::Mod.new(::LDAP::LDAP_MOD_REPLACE, attr.to_s, vals)
end
new(name) click to toggle source

Create an instance of this class, given a name. Note: if an instance already exists, it will return a handle to the existing object.

Calls superclass method
# File lib/whimsy/asf/ldap.rb, line 452
def self.new name
  begin
    object = collection[name]
    return object.reference if object and object.weakref_alive?
  rescue
  end

  super
end
new(name) click to toggle source

create an instance of this class, returning a weak reference to the object for reuse. Note: self.new will check for such a reference and return it in favor of allocating a new object.

# File lib/whimsy/asf/ldap.rb, line 465
def initialize name
  self.class.collection[name] = WeakRef.new(self)
  @name = name
end

Public Instance Methods

<=>(other) click to toggle source

define default sort key (make Base objects sortable)

# File lib/whimsy/asf/ldap.rb, line 418
def <=>(other)
  @name <=> other.name
end
base() click to toggle source

return the LDAP base for this object: identifies the subtree where this object can be found.

# File lib/whimsy/asf/ldap.rb, line 430
def base
  self.class.base
end
id() click to toggle source

Return the simple name for this LDAP object. This is the value of uid for people objects, and the value of cn for all other objects.

# File lib/whimsy/asf/ldap.rb, line 484
def id
  @name
end
reference() click to toggle source

returns a reference to the underlying object. Useful for converting weak references to strong references.

# File lib/whimsy/asf/ldap.rb, line 472
def reference
  self
end
weakref(attr, &block) click to toggle source

construct a weak reference to this object

# File lib/whimsy/asf/ldap.rb, line 477
def weakref(attr, &block)
  ASF.dereference_weakref(self, attr, &block)
end