Class: LDAP::Server::Schema::ObjectClass

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap/server/schema.rb

Overview

Class holding an instance of an ObjectClassDescription (RFC2252 4.4)

Constant Summary collapse

SCAN_WOID =
/#{LDAP::Server::Syntax::WOID}/x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ObjectClass

Returns a new instance of ObjectClass.



528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/ldap/server/schema.rb', line 528

def initialize(str)
  m = LDAP::Server::Syntax::ObjectClassDescription.match(str)
  raise LDAP::ResultError::InvalidAttributeSyntax,
    "Bad ObjectClassDescription #{str.inspect}" unless m
  @oid = m[1]
  @names = (m[2]||"").scan(/'(.*?)'/).flatten
	@desc = m[3]
	@obsolete = ! m[4].nil?
	@sup = (m[5]||"").scan(SCAN_WOID).flatten
  @struct = m[6] ? m[6].downcase.intern : :structural
  @must = (m[7]||"").scan(SCAN_WOID).flatten
  @may = (m[8]||"").scan(SCAN_WOID).flatten
  @def = nil
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def desc
  @desc
end

#mayObject (readonly)

Returns the value of attribute may.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def may
  @may
end

#mustObject (readonly)

Returns the value of attribute must.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def must
  @must
end

#namesObject (readonly)

Returns the value of attribute names.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def names
  @names
end

#obsoleteObject (readonly)

Returns the value of attribute obsolete.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def obsolete
  @obsolete
end

#oidObject (readonly)

Returns the value of attribute oid.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def oid
  @oid
end

#structObject (readonly)

Returns the value of attribute struct.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def struct
  @struct
end

#supObject (readonly)

Returns the value of attribute sup.



524
525
526
# File 'lib/ldap/server/schema.rb', line 524

def sup
  @sup
end

Instance Method Details

#changedObject



551
552
553
# File 'lib/ldap/server/schema.rb', line 551

def changed
  @def = nil
end

#joinoids(pfx, arr, sfx) ⇒ Object



577
578
579
580
581
582
583
584
585
586
# File 'lib/ldap/server/schema.rb', line 577

def joinoids(pfx,arr,sfx)
  return "" unless arr and !arr.empty?
  return "#{pfx}#{arr}#{sfx}" unless arr.is_a?(Array)
  a = arr.collect { |elem| elem.to_s }
  if a.size == 1
    return "#{pfx}#{a.first}#{sfx}"
  else
    return "#{pfx}( #{a.join(" $ ")} )#{sfx}"
  end
end

#nameObject



543
544
545
# File 'lib/ldap/server/schema.rb', line 543

def name
  @names.first
end

#to_defObject



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/ldap/server/schema.rb', line 555

def to_def
  return @def if @def
  ans = "( #{@oid} "
  if @names.nil? or @names.empty?
    # nothing
  elsif @names.size == 1
    ans << "NAME '#{@names.first}' "
  else
    ans << "NAME ( "
    @names.each { |n| ans << "'#{n}' " }
    ans << ") "
  end
  ans << "DESC '#{@desc}' " if @desc
  ans << "OBSOLETE " if @obsolete
  ans << joinoids("SUP ",@sup," ")
  ans << "#{@struct.to_s.upcase} " if @struct
  ans << joinoids("MUST ",@must," ")
  ans << joinoids("MAY ",@may," ")
  ans << ")"
  @def = ans
end

#to_sObject



547
548
549
# File 'lib/ldap/server/schema.rb', line 547

def to_s
  (@names && @names.first) || @oid
end