class LDAP::Server::Filter

Public Class Methods

to_rfc(preserved_filter) click to toggle source
# File lib/rbmk/operation.rb, line 21
def self.to_rfc preserved_filter
        raise ArgumentError, 'Array expected' unless preserved_filter.is_a? Array
        raise ArgumentError, 'Filter is empty' if preserved_filter.empty?
        filter = preserved_filter.clone
        op = filter.shift
        res = case op
                when :not then
                        raise 'Empty subfilter' if (sf = send(__method__, filter)).empty?
                        '!%s' % sf
                when :and then
                        raise 'Empty subfilter' if (sf = filter.map { |f| send(__method__, f) }.join).empty?
                        '&%s' % sf
                when :or
                        raise 'Empty subfilter' if (sf = filter.map { |f| send(__method__, f) }.join).empty?
                        '!%s' % sf

                when :true       then 'objectClass=*'
                when :false      then '!(objectClass=*)'
                when :undef      then raise 'Undefined filter has no RFC representation'

                when :present    then sprintf '%s=*',   filter.first
                when :eq         then sprintf '%s=%s',  filter.first, filter.last
                when :approx     then sprintf '%s~=%s', filter.first, filter.last
                when :ge         then sprintf '%s>=%s', filter.first, filter.last
                when :le         then sprintf '%s<=%s', filter.first, filter.last
                when :substrings then
                        attr = filter.shift
                        junk = filter.shift
                        '%s=%s' % [attr, filter.join('*')]
                else raise 'Unknown op %s' % op.inspect
        end
        '(%s)' % res
rescue
        $!.log_debug
        ''
end