<commit_before>module Volt
  class Model
    # The permissions module provides helpers for working with Volt permissions.
    module Permissions
      module ClassMethods
        # Own by user requires a logged in user (Volt.current_user) to save a model.  If
        # the user is not logged in, an validation error will occur.  Once created
        # the user can not be changed.
        #
        # @param key [Symbol] the name of the attribute to store
        def own_by_user(key = :user_id)
          *resource_name, _discard = key.to_s.split('_')
          belongs_to resource_name.join("_")
          # When the model is created, assign it the user_id (if the user is logged in)
          on(:new) do
            # Only assign the user_id if there isn't already one and the user is logged in.
            if _user_id.nil? && !(user_id = Volt.current_user_id).nil?
              send(:"_#{key}=", user_id)
            end
          end

          on(:create, :update) do
            # Don't allow the key to be changed
            deny(key)<commit_msg>Add informative error message if unable to transform :key parameter<commit_after>module Volt
  class Model
    # The permissions module provides helpers for working with Volt permissions.
    module Permissions
      module ClassMethods
        # Own by user requires a logged in user (Volt.current_user) to save a model.  If
        # the user is not logged in, an validation error will occur.  Once created
        # the user can not be changed.
        #
        # @param key [Symbol] the name of the attribute to store
        def own_by_user(key = :user_id)
          relation, pattern = key.to_s, /_id$/
          if relation.match(pattern)
            belongs_to key.to_s.gsub(pattern, '')
          else
            raise "You tried to auto associate a model using #{key}, but #{key} "\
                  "does not end in `_id`"
          end          # When the model is created, assign it the user_id (if the user is logged in)
          on(:new) do
            # Only assign the user_id if there isn't already one and the user is logged in.
            if _user_id.nil? && !(user_id = Volt.current_user_id).nil?
              send(:"_#{key}=", user_id)
            end
          end

          on(:create, :update) do
            # Don't allow the key to be changed
            deny(key)
{'fraction_non_alphanumeric': 0.07382265591854052, 'fraction_numerical': 0.0, 'mean_word_length': 1.9885931558935361, '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': '5084261', 'n_tokens_mistral': 647, 'n_tokens_neox': 646, 'n_words': 270}