<commit_before>require 'allowance/version'

module Allowance
  def permissions
    @permissions ||= {}
  end

  def define_permissions
    # TODO: log a warning that the subject's define_permissions needs
    #       to be overloaded.
  end

  def allowed?(verb, object = nil)
    unless @permissions_defined
      define_permissions
      @permissions_defined = true
    end

    # Allow access if there is a direct match in permissions.
    return true if permissions[[verb, object]]

    # If object is a resource instance, try its class.
    if object.class.respond_to?(:model_name)
      if allowed?(verb, object.class)
        # See if the object is part of the defined scope.
        return allowed_scope(verb, object.class).exists?(object)
      end
    end

    # Once we get here, access can't be granted.
    false
  end

  def allow(verbs, objects = nil, scope = true, &blk)
    expand_permissions(verbs).each do |verb|
      [objects].flatten.each do |object|
        permissions[[verb, object]] = scope  # TODO: add blk, too
      end<commit_msg>Move evaluation of define_permissions to #permissions accessor.<commit_after>require 'allowance/version'

module Allowance
  def permissions
    unless @permissions_defined
      define_permissions
      @permissions_defined = true
    end

    @permissions || {}
  end

  def define_permissions
    # TODO: log a warning that the subject's define_permissions needs
    #       to be overloaded.
  end

  def allowed?(verb, object = nil)
    # Allow access if there is a direct match in permissions.
    return true if permissions[[verb, object]]

    # If object is a resource instance, try its class.
    if object.class.respond_to?(:model_name)
      if allowed?(verb, object.class)
        # See if the object is part of the defined scope.
        return allowed_scope(verb, object.class).exists?(object)
      end
    end

    # Once we get here, access can't be granted.
    false
  end

  def allow(verbs, objects = nil, scope = true, &blk)
    expand_permissions(verbs).each do |verb|
      [objects].flatten.each do |object|
        @permissions ||= {}
        @permissions[[verb, object]] = scope  # TODO: add blk, too
      end
{'fraction_non_alphanumeric': 0.08371246587807098, 'fraction_numerical': 0.0, 'mean_word_length': 2.8646748681898067, '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': '3575146', 'n_tokens_mistral': 638, 'n_tokens_neox': 628, 'n_words': 222}