<commit_before>class BackerObserver < ActiveRecord::Observer
  observe :backer

  def after_create(backer)
    backer.define_key
    backer.define_payment_method
  end

  def before_save(backer)
    Notification.notify_once(:payment_slip,
      backer.user,
      {backer_id: backer.id},
      backer: backer,
      project: backer.project) if backer.payment_choice_was.nil? && backer.payment_choice == 'BoletoBancario'

    if backer.confirmed? and backer.confirmed_at.nil?
      backer.confirmed_at = Time.now
      Notification.notify_once(:confirm_backer,
        backer.user,
        {backer_id: backer.id},
        backer: backer,
        project: backer.project)

      Notification.notify_once(:project_owner_backer_confirmed,
        backer.project.user,
        {backer_id: backer.id},
        backer: backer,
        project: backer.project)

      if (Time.now > backer.project.expires_at  + 7.days) && (user = User.where(email: ::Configuration[:email_payments]).first)
        Notification.notify_once(:backer_confirmed_after_project_was_closed,
          user,
          {backer_id: backer.id},
          backer: backer,
          project: backer.project)
      end
    end
  end

  def after_save(backer)
    Notification.notify_once(:project_success,
      backer.project.user,
      {project_id: backer.project.id},
      project: backer.project) if backer.project.reached_goal?
  end

  def notify_backoffice(backer)
    CreditsMailer.request_refund_from(backer).deliver
  end

  def notify_backoffice_about_canceled(backer)
    user = User.where(email: Configuration[:email_payments]).first
    if user.present?
      Notification.notify_once(:backer_canceled_after_confirmed,
        user,
        {backer_id: backer.id},
        backer: backer)
    end
  end

end<commit_msg>small refactor to improve backer observer readability<commit_after>class BackerObserver < ActiveRecord::Observer
  observe :backer

  def after_create(backer)
    backer.define_key
    backer.define_payment_method
  end

  def before_save(backer)
    notify_confirmation(backer) if backer.confirmed? && backer.confirmed_at.nil?
    notify_payment_slip(backer) if backer.payment_choice_was.nil? && backer.payment_choice == 'BoletoBancario'
  end

  def after_save(backer)
    if backer.project.reached_goal?
      Notification.notify_once(
        :project_success,
        backer.project.user,
        {project_id: backer.project.id},
        project: backer.project
      ) 
    end
  end

  def notify_backoffice(backer)
    CreditsMailer.request_refund_from(backer).deliver
  end

  def notify_backoffice_about_canceled(backer)
    user = User.where(email: Configuration[:email_payments]).first
    if user.present?
      Notification.notify_once(
        :backer_canceled_after_confirmed,
        user,
        {backer_id: backer.id},
        backer: backer
      )
    end
  end

  private
  def notify_confirmation(backer)
    backer.confirmed_at = Time.now
    Notification.notify_once(
      :confirm_backer,
      backer.user,
      {backer_id: backer.id},
      backer: backer,
      project: backer.project
    )

    Notification.notify_once(
      :project_owner_backer_confirmed,
      backer.project.user,
      {backer_id: backer.id},
      backer: backer,
      project: backer.project
    )

    if (Time.now > backer.project.expires_at  + 7.days) && (user = User.where(email: ::Configuration[:email_payments]).first)
      Notification.notify_once(
        :backer_confirmed_after_project_was_closed,
        user,
        {backer_id: backer.id},
        backer: backer,
        project: backer.project
      )
    end
  end

  def notify_payment_slip(backer)
    Notification.notify_once(
      :payment_slip,
      backer.user,
      {backer_id: backer.id},
      backer: backer,
      project: backer.project
    ) 
  end

end
{'fraction_non_alphanumeric': 0.09105098855359, 'fraction_numerical': 0.0005202913631633715, 'mean_word_length': 2.9844559585492227, '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': '5264022', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1258, 'n_words': 209}