<commit_before>module HeyookRails
  module HasRoles
    def self.included(base)
      base.extend ClassMethods
    end
    
    module InstanceMethods
      def roles=(roles)                  
        self.roles_mask = (roles & defined_roles).map { |r| 2**defined_roles.index(r) }.sum
      end

      def roles
        defined_roles.reject { |r| ((roles_mask || 0) & 2**defined_roles.index(r)).zero? }
      end

      def role?(role)
        roles.include? role.to_s
      end   
    end  
    
    module ClassMethods
      def has_roles *roles
        cattr_accessor :defined_roles
        self.defined_roles = roles.dup.map(&:to_s).freeze
        
        scope :with_role, lambda { |role| where("roles_mask & #{2**defined_roles.index(role.to_s)} > 0") }  
                             <commit_msg>No biggie<commit_after>module HeyookRails
  module HasRoles
    def self.included(base)
      base.extend ClassMethods
    end
    
    module InstanceMethods
      def roles=(roles)                  
        self.roles_mask = (roles & defined_roles).map { |r| 2**defined_roles.index(r) }.sum 
      end

      def roles
        defined_roles.reject { |r| ((roles_mask || 0) & 2**defined_roles.index(r)).zero? }
      end

      def role?(role)
        roles.include? role.to_s
      end
    end  
    
    module ClassMethods
      def has_roles *roles
        
        raise "Must specify at least one role" if roles.empty?          
        
        cattr_accessor :defined_roles, :default_role 
        
        self.default_role = roles.extract_options![:default].to_s
        self.default_role ||= roles.last.to_s
        self.default_role.freeze
        
        self.defined_roles = roles.dup.map(&:to_s).freeze
        
        scope :with_role, lambda { |role| where("roles_mask & #{2**defined_roles.index(role.to_s)} > 0") }  
        
        before_save { self.roles = Array.wrap(default_role) }

{'fraction_non_alphanumeric': 0.10198744769874477, 'fraction_numerical': 0.005230125523012552, 'mean_word_length': 1.965891472868217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3076522', 'n_tokens_mistral': 634, 'n_tokens_neox': 621, 'n_words': 119}