<commit_before>module Adauth
    
    # Module desgined to be included in a ActiveRecord user model
    module UserModel
        
        # Adds class methods to the ActiveRecord model when included
        def self.included(base)
            base.extend ClassMethods
        end
        
        # Returns an array of groups for the user
        #
        # Called as:
        #    UserInstance.groups
        #
        # The array is generated from the group_strings attribute which is set by the adauth update and create methods. This array will match the windows security groups the user is a member of.
    	def groups
    	   group_strings.split(", ") 
	    end
	    
	    # Returns an array of groups for the user
        #
        # Called as:
        #    UserInstance.ous
        #
        # The array is generated from the group_strings attribute which is set by the adauth update and create methods. This array will match the orginizational units the user is a member of.
	    def ous
	        ou_strings.split(", ")
        end
	    
	    # Update the user record using an instance of Adauth::User
	    #
	    # Called as:
	    #    UserInstance.update_from_adauth(AdauthUserInstance)
	    #
	    # This method is called on login and shouldn't need to be called at any other time
	    def update_from_adauth(adauth_user)
	        self.group_strings = adauth_user.groups.join(", ")
	        self.name = adauth_user.name.gsub(/\"|\[|\]/, "")
	        self.save
        end
	    
	    # Class methods for the UserModel
	    module ClassMethods
	        
	        # Used during the login process to return the users database record.
	        #
	        # Takes an instance of Adauth::User as an input
	        #
	        # Called as
	        #     YourUserModel.return_and_create_with_adauth(AdauthUserInstance)
	        #
	        # If the user has no user record in the database one will be created. All the details on the record (new and old) will be updated to the lastest details from the AD server
	        def return_and_create_with_adauth(adauth_user)
                user = (find_by_login(adauth_user.login.gsub(/\"|\[|\]/, "") || create_user_with_adauth(adauth_user))
                user.update_from_adauth(adauth_user)
                return user
            end
            
            # Creates a user record from an instance of Adauth::User
            #
            # Called as:
            #    YourUserModel.create_user_with_adauth(AdauthUserInstance)
            #
            # Takes the Adauth::User input and creates a user record with matching details
            def create_user_with_adauth(adauth_user)
        		create! do |user|
        			user.login = adauth_user.login.gsub(/\"|\[|\]/, "")
        			user.group_strings = adauth_user.groups.join(", ")
        			user.ou_strings = adauth_user.ous.join(", ")
        			user.name = adauth_user.name(/\"|\[|\]/, "")
        		end
        	end 
        end<commit_msg>fixed missing closing paren.<commit_after>module Adauth
    
    # Module desgined to be included in a ActiveRecord user model
    module UserModel
        
        # Adds class methods to the ActiveRecord model when included
        def self.included(base)
            base.extend ClassMethods
        end
        
        # Returns an array of groups for the user
        #
        # Called as:
        #    UserInstance.groups
        #
        # The array is generated from the group_strings attribute which is set by the adauth update and create methods. This array will match the windows security groups the user is a member of.
    	def groups
    	   group_strings.split(", ") 
	    end
	    
	    # Returns an array of groups for the user
        #
        # Called as:
        #    UserInstance.ous
        #
        # The array is generated from the group_strings attribute which is set by the adauth update and create methods. This array will match the orginizational units the user is a member of.
	    def ous
	        ou_strings.split(", ")
        end
	    
	    # Update the user record using an instance of Adauth::User
	    #
	    # Called as:
	    #    UserInstance.update_from_adauth(AdauthUserInstance)
	    #
	    # This method is called on login and shouldn't need to be called at any other time
	    def update_from_adauth(adauth_user)
	        self.group_strings = adauth_user.groups.join(", ")
	        self.name = adauth_user.name.gsub(/\"|\[|\]/, "")
	        self.save
        end
	    
	    # Class methods for the UserModel
	    module ClassMethods
	        
	        # Used during the login process to return the users database record.
	        #
	        # Takes an instance of Adauth::User as an input
	        #
	        # Called as
	        #     YourUserModel.return_and_create_with_adauth(AdauthUserInstance)
	        #
	        # If the user has no user record in the database one will be created. All the details on the record (new and old) will be updated to the lastest details from the AD server
	        def return_and_create_with_adauth(adauth_user)
                user = (find_by_login(adauth_user.login.gsub(/\"|\[|\]/, "")) || create_user_with_adauth(adauth_user))
                user.update_from_adauth(adauth_user)
                return user
            end
            
            # Creates a user record from an instance of Adauth::User
            #
            # Called as:
            #    YourUserModel.create_user_with_adauth(AdauthUserInstance)
            #
            # Takes the Adauth::User input and creates a user record with matching details
            def create_user_with_adauth(adauth_user)
        		create! do |user|
        			user.login = adauth_user.login.gsub(/\"|\[|\]/, "")
        			user.group_strings = adauth_user.groups.join(", ")
        			user.ou_strings = adauth_user.ous.join(", ")
        			user.name = adauth_user.name(/\"|\[|\]/, "")
        		end
        	end 
        end
{'fraction_non_alphanumeric': 0.07022282241728561, 'fraction_numerical': 0.0, 'mean_word_length': 1.8944797264289204, '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': '205103', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1601, 'n_words': 540}