Skip to content

Commit 2769d75

Browse files
author
blackhedd
committed
Added Net::LDAP::Filter.execute, which enables applications to perform
arbitrary processing based on LDAP filters.
1 parent 9840657 commit 2769d75

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lib/net/ldap/filter.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,51 @@ def Filter::parse_ber ber
281281
end
282282

283283

284+
# Perform filter operations against a user-supplied block. This is useful when implementing
285+
# an LDAP directory server. The caller's block will be called with two arguments: first, a
286+
# symbol denoting the "operation" of the filter; and second, an array consisting of arguments
287+
# to the operation. The user-supplied block (which is MANDATORY) should perform some desired
288+
# application-defined processing, and may return a locally-meaningful object that will appear
289+
# as a parameter in the :and, :or and :not operations detailed below.
290+
#
291+
# A typical object to return from the user-supplied block is an array of
292+
# Net::LDAP::Filter objects.
293+
#
294+
# These are the possible values that may be passed to the user-supplied block:
295+
# :equalityMatch (the arguments will be an attribute name and a value to be matched);
296+
# :substrings (two arguments: an attribute name and a value containing one or more * characters);
297+
# :present (one argument: an attribute name);
298+
# :greaterOrEqual (two arguments: an attribute name and a value to be compared against);
299+
# :lessOrEqual (two arguments: an attribute name and a value to be compared against);
300+
# :and (two or more arguments, each of which is an object returned from a recursive call
301+
# to #execute, with the same block;
302+
# :or (two or more arguments, each of which is an object returned from a recursive call
303+
# to #execute, with the same block;
304+
# :not (one argument, which is an object returned from a recursive call to #execute with the
305+
# the same block.
306+
#
307+
def execute &block
308+
case @op
309+
when :eq
310+
if @right == "*"
311+
yield :present, @left
312+
elsif @right.index '*'
313+
yield :substrings, @left, @right
314+
else
315+
yield :equalityMatch, @left, @right
316+
end
317+
when :ge
318+
yield :greaterOrEqual, @left, @right
319+
when :le
320+
yield :lessOrEqual, @left, @right
321+
when :or, :and
322+
yield @op, (@left.execute &block), (@right.execute &block)
323+
when :not
324+
yield @op, (@left.execute &block)
325+
end || []
326+
end
327+
328+
284329
#--
285330
# coalesce
286331
# This is a private helper method for dealing with chains of ANDs and ORs

0 commit comments

Comments
 (0)