<commit_before>require "active_support/concern"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/module/introspection"
require "banken/version"
require "banken/error"
require "banken/helper"
require "banken/policy_finder"

module Banken
  extend ActiveSupport::Concern

  included do
    helper Helper if respond_to?(:helper)
    if respond_to?(:helper_method)
      helper_method :policy
      helper_method :banken_policy_scope
      helper_method :banken_user
    end
    if respond_to?(:hide_action)
      hide_action :policy
      hide_action :policy_scope
      hide_action :policies
      hide_action :policy_scopes
      hide_action :authorize!
      hide_action :verify_authorized
      hide_action :verify_policy_scoped
      hide_action :permitted_attributes
      hide_action :banken_user
      hide_action :skip_authorization
      hide_action :skip_policy_scope
    end
  end

  class << self
    def authorize(user, record, action)
      policy = policy!(user, record)

      unless policy.public_send(action)
        raise NotAuthorizedError.new(action: action, record: record, policy: policy)
      end

      true
    end

    def policy_scope(user, scope)
      policy_scope = PolicyFinder.new(scope).scope
      policy_scope.new(user, scope).resolve if policy_scope
    end

    def policy_scope!(user, scope)
      PolicyFinder.new(scope).scope!.new(user, scope).resolve
    end

    def policy(user, record)
      policy = PolicyFinder.new(record).policy
      policy.new(user, record) if policy
    end

    def policy!(controller, user, record)
      PolicyFinder.new(controller).policy!.new(user, record)
    end
  end

  def banken_policy_authorized?
    !!@_banken_policy_authorized
  end

  def banken_policy_scoped?
    !!@_banken_policy_scoped
  end
<commit_msg>Disallow manually retrieving policies thought Banken module<commit_after>require "active_support/concern"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/module/introspection"
require "banken/version"
require "banken/error"
require "banken/helper"
require "banken/policy_finder"

module Banken
  extend ActiveSupport::Concern

  included do
    helper Helper if respond_to?(:helper)
    if respond_to?(:helper_method)
      helper_method :banken_policy_scope
      helper_method :banken_user
    end
    if respond_to?(:hide_action)
      hide_action :policy
      hide_action :policy_scope
      hide_action :policies
      hide_action :policy_scopes
      hide_action :authorize!
      hide_action :verify_authorized
      hide_action :verify_policy_scoped
      hide_action :permitted_attributes
      hide_action :banken_user
      hide_action :skip_authorization
      hide_action :skip_policy_scope
    end
  end

  class << self
    def authorize(user, record, action)
      policy = policy!(user, record)

      unless policy.public_send(action)
        raise NotAuthorizedError.new(action: action, record: record, policy: policy)
      end

      true
    end

    def policy_scope(user, scope)
      policy_scope = PolicyFinder.new(scope).scope
      policy_scope.new(user, scope).resolve if policy_scope
    end

    def policy_scope!(user, scope)
      PolicyFinder.new(scope).scope!.new(user, scope).resolve
    end

    def policy!(controller, user, record)
      PolicyFinder.new(controller).policy!.new(user, record)
    end
  end

  def banken_policy_authorized?
    !!@_banken_policy_authorized
  end

  def banken_policy_scoped?
    !!@_banken_policy_scoped
  end

{'fraction_non_alphanumeric': 0.07601536772777168, 'fraction_numerical': 0.0, 'mean_word_length': 3.685089974293059, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1944502', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1098, 'n_words': 242}