<commit_before># encoding: utf-8

#require "digest/md5"
#require "digest/sha1"
#require "rails"
   
module Fjomp
  module Authorization
    class Role < ActiveRecord::Base
      has_many :users
      has_and_belongs_to_many :permissions
  
      validates_presence_of :name
      validates_uniqueness_of :name
    end

    class Permission < ActiveRecord::Base
      has_and_belongs_to_many :roles
      validates_presence_of :name
      validates_uniqueness_of :name
    end

    # Called automatically when this module is loaded
    def self.included(base)
      base.send :extend, ClassMethods
    end


    module ClassMethods
      def acts_as_user(*args)
        # Each user has a single role
        belongs_to :role
  
        # Access permissions of the users role directly
        delegate :permissions, :to => :role
  
        # Create getter and setter for passwrd
        attr_accessor :password
  
        # White-list for mass-assignment
        attr_accessible :username, :password, :password_confirmation
        attr_accessible :role_id
      
        before_create :generate_password_hash
        before_update :generate_password_hash
        after_create  :forget_plain_text_password
        after_save    :forget_plain_text_password<commit_msg>testing<commit_after># encoding: utf-8

#require "digest/md5"
#require "digest/sha1"
#require "rails"
   
module Fjomp
  module Authorization
    # Called automatically when this module is loaded
    def self.included(base)
      base.send :extend, UserClassMethods
      base.send :extend, RoleClassMethods
      base.send :extend, PermissionClassMethods
    end

    module RoleClassMethods
      def acts_as_role
        has_many :users
        has_and_belongs_to_many :permissions
        validates_presence_of :name
        validates_uniqueness_of :name
      end
    end

    module PermissionClassMethods
      def acts_as_permission
        has_and_belongs_to_many :roles
        validates_presence_of :name
        validates_uniqueness_of :name
      end
    end

    module UserClassMethods
      def acts_as_user(*args)
        # Each user has a single role
        belongs_to :role
  
        # Access permissions of the users role directly
        delegate :permissions, :to => :role
  
        # Create getter and setter for passwrd
        attr_accessor :password
  
        # White-list for mass-assignment
        attr_accessible :username, :password, :password_confirmation
        attr_accessible :role_id
      
        before_create :generate_password_hash
        before_update :generate_password_hash
        after_create  :forget_plain_text_password
        after_save    :forget_plain_text_password
{'fraction_non_alphanumeric': 0.047619047619047616, 'fraction_numerical': 0.002232142857142857, 'mean_word_length': 2.708965517241379, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2442101', 'n_tokens_mistral': 789, 'n_tokens_neox': 766, 'n_words': 201}