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 functional 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
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
Find an instance of this class, given a name
# File lib/whimsy/asf/ldap.rb, line 465 def self.[](name) new(name) end
return the LDAP
base for this object: identifies the subtree where this object can be found.
# File lib/whimsy/asf/ldap.rb, line 448 def self.base @base end
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 460 def self.collection @collection ||= {} end
Find an instance of this class, given a name
# File lib/whimsy/asf/ldap.rb, line 470 def self.find(name) new(name) end
helper method to construct LDAP_MOD_ADD objects
# File lib/whimsy/asf/ldap.rb, line 514 def self.mod_add(attr, vals) ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, attr.to_s, Array(vals)) end
helper method to construct LDAP_MOD_DELETE objects
# File lib/whimsy/asf/ldap.rb, line 525 def self.mod_delete(attr, vals) ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, attr.to_s, Array(vals)) end
helper method to construct LDAP_MOD_REPLACE objects
# File lib/whimsy/asf/ldap.rb, line 519 def self.mod_replace(attr, vals) vals = Array(vals) unless vals.is_a? Hash ::LDAP::Mod.new(::LDAP::LDAP_MOD_REPLACE, attr.to_s, vals) end
Create an instance of this class, given a name. Note: if an instance already exists, it will return a handle to the existing object.
# File lib/whimsy/asf/ldap.rb, line 476 def self.new(name) begin object = collection[name] return object.reference if object&.weakref_alive? rescue end super end
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 489 def initialize(name) self.class.collection[name] = WeakRef.new(self) @name = name end
Public Instance Methods
define default sort key (make Base
objects sortable)
# File lib/whimsy/asf/ldap.rb, line 442 def <=>(other) @name <=> other.name end
return the LDAP
base for this object: identifies the subtree where this object can be found.
# File lib/whimsy/asf/ldap.rb, line 454 def base self.class.base end
# File lib/whimsy/asf/ldap.rb, line 529 def hasLDAP? ASF.search_one(base, "cn=#{name}", 'cn').any? end
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 509 def id @name end
returns a reference to the underlying object. Useful for converting weak references to strong references.
# File lib/whimsy/asf/ldap.rb, line 496 def reference self end
construct a weak reference to this object N.B. weakref(:XYZ) stores the reference in @XYZ
# File lib/whimsy/asf/ldap.rb, line 502 def weakref(attr, &block) ASF.dereference_weakref(self, attr, &block) end