lib/treequel/branch.rb in treequel-1.1.1 vs lib/treequel/branch.rb in treequel-1.2.0pre320

- old
+ new

@@ -15,11 +15,12 @@ # for the entries below itself, and how to search for those entries. class Treequel::Branch include Comparable, Treequel::Loggable, Treequel::Constants, - Treequel::Constants::Patterns + Treequel::Constants::Patterns, + Treequel::HashUtilities extend Treequel::Delegation, Treequel::AttributeDeclarations @@ -50,10 +51,11 @@ ### @param [LDAP::Entry] entry The raw entry object the Branch is wrapping. ### @param [Treequel::Directory] directory The directory object the Branch is from. ### ### @return [Treequel::Branch] The new branch object. def self::new_from_entry( entry, directory ) + entry = Treequel::HashUtilities.stringify_keys( entry ) return self.new( directory, entry['dn'].first, entry ) end ################################################################# @@ -74,11 +76,11 @@ raise ArgumentError, "can't cast a %s to an LDAP::Entry" % [entry.class.name] unless entry.nil? || entry.is_a?( Hash ) @directory = directory @dn = dn - @entry = entry + @entry = entry ? stringify_keys( entry ) : nil @values = {} @include_operational_attrs = self.class.include_operational_attrs? end @@ -285,15 +287,17 @@ ### @return [Array, String] def []( attrname ) attrsym = attrname.to_sym unless @values.key?( attrsym ) + self.log.debug " value for %p is NOT cached." % [ attrsym ] value = self.get_converted_object( attrsym ) + self.log.debug " converted value is: %p" % [ value ] value.freeze if value.respond_to?( :freeze ) @values[ attrsym ] = value else - self.log.debug " value is cached." + self.log.debug " value for %p is cached." % [ attrname ] end return @values[ attrsym ] end @@ -472,23 +476,26 @@ ### merge them with the current list of the current objectClasses for the lookup. ### ### @param [Array<String, Symbol>] additional_classes ### @return [Array<Treequel::Schema::ObjectClass>] def object_classes( *additional_classes ) + self.log.debug "Fetching object classes for %s" % [ self.dn ] schema = self.directory.schema oc_oids = self[:objectClass] || [] + self.log.debug " objectClass OIDs are: %p" % [ oc_oids ] oc_oids |= additional_classes.collect {|str| str.to_sym } - oc_oids << 'top' if oc_oids.empty? + oc_oids << :top if oc_oids.empty? oclasses = [] oc_oids.each do |oid| oc = schema.object_classes[ oid.to_sym ] or raise Treequel::Error, "schema doesn't have a %p objectClass" % [ oid ] oclasses << oc end + self.log.debug " found %d objectClasses: %p" % [ oclasses.length, oclasses ] return oclasses.uniq end ### Return the receiver's operational attributes as attributeType schema objects. @@ -515,11 +522,12 @@ ### @param [Array<String, Symbol>] additional_object_classes ### @return [Array<Treequel::Schema::AttributeType>] def must_attribute_types( *additional_object_classes ) types = [] oclasses = self.object_classes( *additional_object_classes ) - self.log.debug "Gathering MUST attribute types for objectClasses: %p" % [ oclasses ] + self.log.debug "Gathering MUST attribute types for objectClasses: %p" % + [ oclasses.map(&:name) ] oclasses.each do |oc| self.log.debug " adding %p from %p" % [ oc.must, oc ] types |= oc.must end @@ -732,16 +740,22 @@ end ### Fetch the entry from the Branch's directory. def lookup_entry + self.log.debug "Looking up entry for %s" % [ self.dn ] + entry = nil + if self.include_operational_attrs? self.log.debug " including operational attributes." - return self.directory.get_extended_entry( self ) + entry = self.directory.get_extended_entry( self ) else self.log.debug " not including operational attributes." - return self.directory.get_entry( self ) + entry = self.directory.get_entry( self ) end + + self.log.debug " entry is: %p" % [ entry ] + return entry end ### Get the value associated with +attrsym+, convert it to a Ruby object if the Branch's ### directory has a conversion rule, and return it.