MatchingRule

class
Superclass
Object
Included Modules
Treequel::Constants::Patterns
Extended With
Loggability
Treequel::AttributeDeclarations

This is a class for representing matchingRule declarations in a Treequel::Schema.

Attributes

desc[RW]

The matchingRule's description

extensions[RW]

The matchingRule's extensions (as a String)

names[R]

The Array of the matchingRule's names

oid[R]

The matchingRule's oid

schema[R]

The schema the matchingRule belongs to

syntax_oid[RW]

The oid of the matchingRule's SYNTAX

Public Class Methods

anchor
new( schema, oid, syntax_oid, names=nil, desc=nil, obsolete=false, extensions=nil )

Create a new MatchingRule

# File lib/treequel/schema/matchingrule.rb, line 48
def initialize( schema, oid, syntax_oid, names=nil, desc=nil, obsolete=false, extensions=nil )

        @schema     = schema

        @oid        = oid
        @syntax_oid = syntax_oid
        @names      = names
        @desc       = desc
        @obsolete   = obsolete ? true : false
        @extensions = extensions

        super()
end
anchor
parse( schema, description )

Parse an MatchingRule entry from a matchingRule description from a schema.

# File lib/treequel/schema/matchingrule.rb, line 27
def self::parse( schema, description )
        unless match = ( LDAP_MATCHING_RULE_DESCRIPTION.match(description) )
                raise Treequel::ParseError, "failed to parse matchingRule from %p" % [ description ]
        end

        oid, names, desc, obsolete, syntax_oid, extensions = match.captures
        # Treequel.logger.debug "  parsed matchingRule: %p" % [ match.captures ]

        # Normalize the attributes
        names = Treequel::Schema.parse_names( names )
        desc  = Treequel::Schema.unquote_desc( desc )

        return self.new( schema, oid, syntax_oid, names, desc, obsolete, extensions )
end

Public Instance Methods

anchor
inspect()

Return a human-readable representation of the object suitable for debugging

# File lib/treequel/schema/matchingrule.rb, line 120
def inspect
        return "#<%s:0x%0x %s(%s) %s %sSYNTAX: %p>" % [
                self.class.name,
                self.object_id / 2,
                self.name,
                self.oid,
                self.desc,
                self.obsolete? ? "(OBSOLETE)" : '',
                self.syntax,
        ]
end
anchor
name()

Return the first of the matchingRule's names, if it has any, or nil.

# File lib/treequel/schema/matchingrule.rb, line 90
def name
        return self.names.first
end
anchor
syntax()

Return the Treequel::Schema::LDAPSyntax object that corresponds to the matchingRule's SYNTAX attribute.

# File lib/treequel/schema/matchingrule.rb, line 135
def syntax
        return self.schema.ldap_syntaxes[ self.syntax_oid ]
end
anchor
to_s()

Returns the matchingRule as a String, which is the RFC4512-style schema description.

# File lib/treequel/schema/matchingrule.rb, line 105
def to_s
        parts = [ self.oid ]

        parts << "NAME %s" % Treequel::Schema.qdescrs( self.names ) unless self.names.empty?

        parts << "DESC '%s'" % [ self.desc ]           if self.desc
        parts << "OBSOLETE"                            if self.obsolete?
        parts << "SYNTAX %s" % [ self.syntax_oid ]
        parts << self.extensions.strip             unless self.extensions.empty?

        return "( %s )" % [ parts.join(' ') ]
end