<commit_before>module GitHub
  class Ldap
    module Filter
      ALL_GROUPS_FILTER = Net::LDAP::Filter.eq("objectClass", "groupOfNames") |
                          Net::LDAP::Filter.eq("objectClass", "groupOfUniqueNames") |
                          Net::LDAP::Filter.eq("objectClass", "posixGroup")

      MEMBERSHIP_NAMES  = %w(member uniqueMember)

      # Filter to get the configured groups in the ldap server.
      # Takes the list of the group names and generate a filter for the groups
      # with cn that match.
      #
      # group_names: is an array of group CNs.
      #
      # Returns a Net::LDAP::Filter.
      def group_filter(group_names)
        group_names.map {|g| Net::LDAP::Filter.eq("cn", g)}.reduce(:|)
      end

      # Filter to check a group membership.
      #
      # entry: is an optional Net::LDAP::Entry to scope the search to.
      #
      # Returns a Net::LDAP::Filter.
      def member_filter(entry = nil)
        if entry
          MEMBERSHIP_NAMES.map {|n| Net::LDAP::Filter.eq(n, entry.dn) }.
                           reduce(:|) |
          entry[@ldap.uid].map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
                           reduce(:|)
        else
          (MEMBERSHIP_NAMES + %w(memberUid)).
            map {|n| Net::LDAP::Filter.pres(n)}.reduce(:|)
        end
      end

      # Filter to map a uid with a login.
      # It escapes the login before creating the filter.
      #
      # uid: the entry field to map.
      # login: the login to map.
      #
      # Returns a Net::LDAP::Filter.<commit_msg>Accept memberUid uid attribute as parameter, better doco<commit_after>module GitHub
  class Ldap
    module Filter
      ALL_GROUPS_FILTER = Net::LDAP::Filter.eq("objectClass", "groupOfNames") |
                          Net::LDAP::Filter.eq("objectClass", "groupOfUniqueNames") |
                          Net::LDAP::Filter.eq("objectClass", "posixGroup")

      MEMBERSHIP_NAMES  = %w(member uniqueMember)

      # Filter to get the configured groups in the ldap server.
      # Takes the list of the group names and generate a filter for the groups
      # with cn that match.
      #
      # group_names: is an array of group CNs.
      #
      # Returns a Net::LDAP::Filter.
      def group_filter(group_names)
        group_names.map {|g| Net::LDAP::Filter.eq("cn", g)}.reduce(:|)
      end

      # Filter to check group membership.
      #
      # entry:    finds groups this Net::LDAP::Entry is a member of (optional)
      # uid_attr: specifies the memberUid attribute to match with   (optional)
      #
      # Returns a Net::LDAP::Filter.
      def member_filter(entry = nil, uid_attr = @ldap.uid)
        if entry
          MEMBERSHIP_NAMES.map {|n| Net::LDAP::Filter.eq(n, entry.dn) }.
                           reduce(:|) |
          entry[uid_attr]. map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
                           reduce(:|)
        else
          (MEMBERSHIP_NAMES + %w(memberUid)).
            map {|n| Net::LDAP::Filter.pres(n)}.reduce(:|)
        end
      end

      # Filter to map a uid with a login.
      # It escapes the login before creating the filter.
      #
      # uid: the entry field to map.
      # login: the login to map.
      #
      # Returns a Net::LDAP::Filter.
{'fraction_non_alphanumeric': 0.1172539489671932, 'fraction_numerical': 0.0, 'mean_word_length': 2.012808783165599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2727842', 'n_tokens_mistral': 1010, 'n_tokens_neox': 1001, 'n_words': 283}