Class: ASF::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/whimsy/asf/ldap.rb,
lib/whimsy/asf/committee.rb

Direct Known Subclasses

Committee, Group, Person, Service

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Base

Returns a new instance of Base.



362
363
364
365
# File 'lib/whimsy/asf/ldap.rb', line 362

def initialize name
  self.class.collection[name] = WeakRef.new(self)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



325
326
327
# File 'lib/whimsy/asf/ldap.rb', line 325

def name
  @name
end

Class Method Details

.[](name) ⇒ Object



344
345
346
# File 'lib/whimsy/asf/ldap.rb', line 344

def self.[] name
  new(name)
end

.baseObject



332
333
334
# File 'lib/whimsy/asf/ldap.rb', line 332

def self.base
  @base
end

.collectionObject



340
341
342
# File 'lib/whimsy/asf/ldap.rb', line 340

def self.collection
  @collection ||= Hash.new
end

.find(name) ⇒ Object



348
349
350
# File 'lib/whimsy/asf/ldap.rb', line 348

def self.find name
  new(name)
end

.mod_add(attr, vals) ⇒ Object



381
382
383
# File 'lib/whimsy/asf/ldap.rb', line 381

def self.mod_add(attr, vals)
  ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, attr.to_s, Array(vals))
end

.mod_delete(attr, vals) ⇒ Object



390
391
392
# File 'lib/whimsy/asf/ldap.rb', line 390

def self.mod_delete(attr, vals)
  ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, attr.to_s, Array(vals))
end

.mod_replace(attr, vals) ⇒ Object



385
386
387
388
# File 'lib/whimsy/asf/ldap.rb', line 385

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) ⇒ Object



352
353
354
355
356
357
358
359
360
# File 'lib/whimsy/asf/ldap.rb', line 352

def self.new name
  begin
    object = collection[name]
    return object.reference if object and object.weakref_alive?
  rescue
  end

  super
end

Instance Method Details

#<=>(other) ⇒ Object

define default sort key (make Base objects sortable)



328
329
330
# File 'lib/whimsy/asf/ldap.rb', line 328

def <=>(other)
  @name <=> other.name
end

#baseObject



336
337
338
# File 'lib/whimsy/asf/ldap.rb', line 336

def base
  self.class.base
end

#idObject



376
377
378
# File 'lib/whimsy/asf/ldap.rb', line 376

def id
  @name
end

#referenceObject



367
368
369
# File 'lib/whimsy/asf/ldap.rb', line 367

def reference
  self
end

#weakref(attr, &block) ⇒ Object



371
372
373
# File 'lib/whimsy/asf/ldap.rb', line 371

def weakref(attr, &block)
  ASF.dereference_weakref(self, attr, &block)
end