lib/treequel/schema.rb in treequel-1.11.0 vs lib/treequel/schema.rb in treequel-1.12.0

- old
+ new

@@ -1,22 +1,23 @@ -#!/usr/bin/env ruby +# -*- ruby -*- +#encoding: utf-8 require 'ldap' require 'ldap/schema' require 'treequel' require 'treequel/constants' require 'treequel/mixins' # This is an object that is used to parse and query a directory's schema -# +# # == Authors -# +# # * Michael Granger <ged@FaerieMUD.org> # * Mahlon E. Smith <mahlon@martini.nu> -# +# # :include: LICENSE # #-- # # Please see the file LICENSE in the base directory for licensing details. @@ -66,11 +67,11 @@ end oids = $MATCH # Treequel.logger.debug " found OIDs: %p" % [ oids ] - # If it's an OIDLIST, strip off leading and trailing parens and whitespace, then split + # If it's an OIDLIST, strip off leading and trailing parens and whitespace, then split # on ' $ ' and parse each OID if oids.include?( '$' ) parse_oid = self.method( :parse_oid ) return $MATCH[1..-2].strip.split( /#{WSP} #{DOLLAR} #{WSP}/x ).collect( &parse_oid ) @@ -114,19 +115,19 @@ return [ names[1..-2].untaint.to_sym ] end end - ### Return a new string which is +desc+ with quotes stripped and any escaped characters + ### Return a new string which is +desc+ with quotes stripped and any escaped characters ### un-escaped. def self::unquote_desc( desc ) return nil if desc.nil? return desc.gsub( QQ, "'" ).gsub( QS, '\\' )[ 1..-2 ] end - ### Return a description of the given +descriptors+ suitable for inclusion in + ### Return a description of the given +descriptors+ suitable for inclusion in ### an RFC4512-style schema description entry. def self::qdescrs( *descriptors ) descriptors.flatten! if descriptors.length > 1 return "( %s )" % [ descriptors.collect {|str| self.qdstring(str) }.join(" ") ] @@ -136,26 +137,26 @@ end # qdstring = SQUOTE dstring SQUOTE # dstring = 1*( QS / QQ / QUTF8 ) ; escaped UTF-8 string - # + # # QQ = ESC %x32 %x37 ; "\27" # QS = ESC %x35 ( %x43 / %x63 ) ; "\5C" / "\5c" - # + # # ; Any UTF-8 encoded Unicode character # ; except %x27 ("\'") and %x5C ("\") # QUTF8 = QUTF1 / UTFMB - ### Escape and quote the specified +string+ according to the rules in + ### Escape and quote the specified +string+ according to the rules in ### RFC4512/2252. def self::qdstring( string ) return "'%s'" % [ string.to_s.gsub(/\\/, '\\\\5c').gsub(/'/, '\\\\27') ] end - ### Return a description of the given +oids+ suitable for inclusion in + ### Return a description of the given +oids+ suitable for inclusion in ### an RFC4512-style schema description entry. def self::oids( *oids ) oids.flatten! if oids.length > 1 return "( %s )" % [ oids.join(" $ ") ] @@ -170,11 +171,11 @@ ### I N S T A N C E M E T H O D S ################################################################# ### Create a new Treequel::Schema from the specified +hash+. The +hash+ should be of the same ### form as the one returned by LDAP::Conn.schema, i.e., a Hash of Arrays associated with the - ### keys "objectClasses", "ldapSyntaxes", "matchingRuleUse", "attributeTypes", and + ### keys "objectClasses", "ldapSyntaxes", "matchingRuleUse", "attributeTypes", and ### "matchingRules". def initialize( hash ) @object_classes = self.parse_objectclasses( hash['objectClasses'] || [] ) @attribute_types = self.parse_attribute_types( hash['attributeTypes'] || [] ) @ldap_syntaxes = self.parse_ldap_syntaxes( hash['ldapSyntaxes'] || [] ) @@ -185,19 +186,19 @@ ###### public ###### - # The table of Treequel::Schema::ObjectClass objects, keyed by OID and any associated NAME + # The table of Treequel::Schema::ObjectClass objects, keyed by OID and any associated NAME # attributes (as Symbols), that describes the objectClasses in the directory's schema. attr_reader :object_classes # The hash of Treequel::Schema::AttributeType objects, keyed by OID and any associated NAME # attributes (as Symbols), that describe the attributeTypes in the directory's schema. attr_reader :attribute_types - # The hash of Treequel::Schema::LDAPSyntax objects, keyed by OID, that describe the + # The hash of Treequel::Schema::LDAPSyntax objects, keyed by OID, that describe the # syntaxes in the directory's schema. attr_reader :ldap_syntaxes # The hash of Treequel::Schema::MatchingRule objects, keyed by OID and any associated NAME # attributes (as Symbols), that describe the matchingRules int he directory's schema. @@ -259,11 +260,11 @@ end end ### Parse the given attributeType +descriptions+ into Treequel::Schema::AttributeType objects - ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes + ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes ### (if it has any). def parse_attribute_types( descriptions ) return descriptions.inject( Treequel::Schema::Table.new ) do |table, desc| begin attrtype = Treequel::Schema::AttributeType.parse( self, desc ) @@ -302,11 +303,11 @@ end end ### Parse the given matchingRule +descriptions+ into Treequel::Schema::MatchingRule objects - ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes + ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes ### (if it has any). def parse_matching_rules( descriptions ) descriptions ||= [] return descriptions.inject( Treequel::Schema::Table.new ) do |table, desc| begin @@ -325,11 +326,11 @@ end end ### Parse the given matchingRuleUse +descriptions+ into Treequel::Schema::MatchingRuleUse objects - ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes + ### and return them as a Hash keyed both by numeric OID and by each of its NAME attributes ### (if it has any). def parse_matching_rule_uses( descriptions ) descriptions ||= [] return descriptions.inject( Treequel::Schema::Table.new ) do |table, desc| begin @@ -353,10 +354,10 @@ def ivar_descriptions self.instance_variables.sort.collect do |ivar| next unless ivar.respond_to?( :length ) len = self.instance_variable_get( ivar ).length "%d %s" % [ len, ivar.to_s.gsub(/_/, ' ')[1..-1] ] - end + end end end # class Treequel::Schema