<commit_before>module AuditedActions
  class AuditedActionsLogEntry
    include Mongoid::Document
    include Mongoid::Timestamps

    # belongs_to :actor
    field :_actor, type: Hash
    #attr_readonly :_actor

    field :controller, type: String
    field :action, type: String
    field :action_object_id, type: String
    field :fullpath, type: String

    field :_associations, type: Hash
    #attr_readonly :_associations

    field :audited_at, type: DateTime

    # belongs_to :user
    def actor
      @actor ||= find_associated_model(_actor)
    end

    def method_missing(method, *args)
      @associated_models ||= {}
      meth_s = method.to_s
      # associated model and was found?
      return @associated_models[meth_s] if @associated_models.has_key?(meth_s)
      # try to find method name in the associations
      if association?(meth_s)
        aattr = _associations[meth_s]
        m = find_and_instantiate_associated_models(aattr)

        m ? (@associated_models[meth_s] = m) : aattr
      else
        # is not association
        super
      end
    end

    def reload_associations
      _associations.each do |name, value|
        m = find_and_instantiate_associated_models(value)
        @associated_models[name] = m if m
      end
    end

    def association?(method)
      _associations.has_key?(method.to_s)
    end<commit_msg>return nil when association was not found in the DB instead its source Hash<commit_after>module AuditedActions
  class AuditedActionsLogEntry
    include Mongoid::Document
    include Mongoid::Timestamps

    # belongs_to :actor
    field :_actor, type: Hash
    #attr_readonly :_actor

    field :controller, type: String
    field :action, type: String
    field :action_object_id, type: String
    field :fullpath, type: String

    field :_associations, type: Hash
    #attr_readonly :_associations

    field :audited_at, type: DateTime

    # belongs_to :user
    def actor
      @actor ||= find_associated_model(_actor)
    end

    def method_missing(method, *args)
      @associated_models ||= {}
      meth_s = method.to_s
      # associated model and was found?
      return @associated_models[meth_s] if @associated_models.has_key?(meth_s)
      # try to find method name in the associations
      if association?(meth_s)
        aattr = _associations[meth_s]
        if model?(aattr)
          @associated_models[meth_s] = find_and_instantiate_associated_models(aattr)
        else
          aattr
        end
      else
        # is not association
        super
      end
    end

    def reload_associations
      _associations.each do |name, value|
        m = find_and_instantiate_associated_models(value)
        @associated_models[name] = m if m
      end
    end

    def association?(method)
      _associations.has_key?(method.to_s)
    end
{'fraction_non_alphanumeric': 0.07150442477876107, 'fraction_numerical': 0.0, 'mean_word_length': 2.824086603518268, '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': '6341932', 'n_tokens_mistral': 880, 'n_tokens_neox': 835, 'n_words': 227}