<commit_before>class Impression < ActiveRecord::Base
  attr_accessible :impressionable_type, :impressionable_id, :user_id,
  :controller_name, :action_name, :view_name, :request_hash, :ip_address,
  :session_hash, :message, :referrer

  belongs_to :impressionable, :polymorphic=>true

  after_save :update_impressions_counter_cache

  private

  def update_impressions_counter_cache
    impressionable_class = self.impressionable_type.constantize

    if impressionable_class.impressionist_counter_cache_options
      resouce = impressionable_class.find(self.impressionable_id)
      resouce.try(:update_impressionist_counter_cache)
    end
  end
end<commit_msg>Non-restful controllers - controllers without models / resources - would cause impressionist to throw an error on impression create, because it was unable to update the model counter cache due to lack of an impressionable_type and impressionable_id. An if statement around the counter-cache method on impressionable_type and impressionable_id solves this.<commit_after>class Impression < ActiveRecord::Base
  attr_accessible :impressionable_type, :impressionable_id, :user_id,
  :controller_name, :action_name, :view_name, :request_hash, :ip_address,
  :session_hash, :message, :referrer

  belongs_to :impressionable, :polymorphic=>true

  after_save :update_impressions_counter_cache

  private

  def update_impressions_counter_cache
    if self.impressionable_type && self.impressionable_id
      impressionable_class = self.impressionable_type.constantize
      if impressionable_class.impressionist_counter_cache_options
        resouce = impressionable_class.find(self.impressionable_id)
        resouce.try(:update_impressionist_counter_cache)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.05973578403216542, 'fraction_numerical': 0.0, 'mean_word_length': 5.8853754940711465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6608981', 'n_tokens_mistral': 521, 'n_tokens_neox': 510, 'n_words': 115}