<commit_before>module Canner

  class Policy

    def initialize(current_user, method, current_branch=nil)
      @current_user = current_user
      @current_branch = current_branch
      @method = method.to_sym
      @roles = fetch_roles
    end

    # implement this in your policy class
    # expects an array or strings or symbols that represent the user roles
    def fetch_roles
      raise ArgumentError.new("YOU NEED TO IMPLEMENT")
      # ex. @current_user.roles
    end

    # implement in your policy class to auto scope in an action
    def canner_scope
      raise ArgumentError.new("NOT IMPLEMENTED")
      # ex:
      # case @method
      # when :index
      #   User.by_branch(@current_branch)
      # else
      #   User.none
      # end
    end

    # implment in your policy class.
    # return true when the user can access the action or resource and false when they can't
    def can?
      raise ArgumentError.new("NOT IMPLEMENTED")
      # ex:
      # case @method
      # when :index, :show
      #   has_role?(:admin)
      # else
      #   false
      # end
    end<commit_msg>Default fetch_roles so nothing needs done in that situation.<commit_after>module Canner

  class Policy

    def initialize(current_user, method, current_branch=nil)
      @current_user = current_user
      @current_branch = current_branch
      @method = method.to_sym
      @roles = fetch_roles
    end

    # if you handle your roles differently you'll need to override.
    # use: rails g canner:fetch_roles
    # expects an array or strings or symbols that represent the user roles
    def fetch_roles
      @current_user.roles
    end

    # implement in your policy class to auto scope in an action
    def canner_scope
      raise ArgumentError.new("NOT IMPLEMENTED")
      # ex:
      # case @method
      # when :index
      #   User.by_branch(@current_branch)
      # else
      #   User.none
      # end
    end

    # implment in your policy class.
    # return true when the user can access the action or resource and false when they can't
    def can?
      raise ArgumentError.new("NOT IMPLEMENTED")
      # ex:
      # case @method
      # when :index, :show
      #   has_role?(:admin)
      # else
      #   false
      # end
    end
{'fraction_non_alphanumeric': 0.06610470275066549, 'fraction_numerical': 0.0, 'mean_word_length': 2.2823871906841338, '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': '4185956', 'n_tokens_mistral': 658, 'n_tokens_neox': 645, 'n_words': 225}