<commit_before>require Talky::Engine.validator_path(:language)

class Post < ActiveRecord::Base

  # Associations
  belongs_to :forum, :counter_cache => true
  belongs_to :topic, :counter_cache => true, :touch => true
  belongs_to :user, :class_name => 'User', :counter_cache => true

  # Accessors
  attr_accessible :body

  # Validations
  validates :body, :user, :topic, :forum, :presence => true
  validates :body, :language => true, if: :language?

  # Default Scope
  default_scope :order => 'created_at ASC'

  # Scope to display only the last n posts. Used for "Recent Posts" display
  scope :recent, lambda {
    |c| reorder('created_at desc').limit(c)
  }

  # Callbacks
  before_save :topic_locked?
  after_save :send_notifications

  # Delegates
  delegate :language, :language?, to: :forum

  # Methods
  private
    def topic_locked?
      if topic.locked?
        errors.add(:base, "That topic is locked")
        false
      end
    end

    def send_notifications
      return if user.admin?
      emails = ::User.admins.map(&:email).compact
      return if emails.empty?

      PostsMailer.delay.send_notification_email(emails, post_url_options: { id: id },
                                                        topic_url_options: { id: topic.id },
                                                        topic: topic.title,
                                                        user: user.title,
                                                        message: body)
    end
end
<commit_msg>Posts' letter url uses slugs<commit_after>require Talky::Engine.validator_path(:language)

class Post < ActiveRecord::Base

  # Associations
  belongs_to :forum, :counter_cache => true
  belongs_to :topic, :counter_cache => true, :touch => true
  belongs_to :user, :class_name => 'User', :counter_cache => true

  # Accessors
  attr_accessible :body

  # Validations
  validates :body, :user, :topic, :forum, :presence => true
  validates :body, :language => true, if: :language?

  # Default Scope
  default_scope :order => 'created_at ASC'

  # Scope to display only the last n posts. Used for "Recent Posts" display
  scope :recent, lambda {
    |c| reorder('created_at desc').limit(c)
  }

  # Callbacks
  before_save :topic_locked?
  after_save :send_notifications

  # Delegates
  delegate :language, :language?, to: :forum

  # Methods
  private
    def topic_locked?
      if topic.locked?
        errors.add(:base, "That topic is locked")
        false
      end
    end

    def send_notifications
      return if user.admin?
      emails = ::User.admins.map(&:email).compact
      return if emails.empty?

      PostsMailer.delay.send_notification_email(emails, post_url_options: { id: to_param },
                                                        topic_url_options: { id: topic.to_param },
                                                        topic: topic.title,
                                                        user: user.title,
                                                        message: body)
    end
end

{'fraction_non_alphanumeric': 0.09459901800327332, 'fraction_numerical': 0.0, 'mean_word_length': 2.028741328047572, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2531385', 'n_tokens_mistral': 868, 'n_tokens_neox': 832, 'n_words': 232}