<commit_before>class DeviseMailer < ::ActionMailer::Base

  # Deliver confirmation instructions when the user is created or its email is
  # updated, and also when confirmation is manually requested
  def confirmation_instructions(record)
    setup_mail(record, :confirmation_instructions)
  end

  # Deliver reset password instructions when manually requested
  def reset_password_instructions(record)
    setup_mail(record, :reset_password_instructions)
  end

  private

    # Configure default email options
    def setup_mail(record, key)
      mapping = Devise::Mapping.find_by_class(record.class)
      raise "Invalid devise resource #{record}" unless mapping

      subject      translate(mapping, key)
      from         Devise.mailer_sender
      recipients   record.email
      sent_on      Time.now
      content_type 'text/html'
      body         render_with_scope(key, mapping, mapping.name => record, :resource => record)
    end

    def render_with_scope(key, mapping, assigns)
      if Devise.scoped_views
        begin
          render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
        rescue ActionView::MissingTemplate
          render :file => "devise_mailer/#{key}", :body => assigns
        end
      else
        render :file => "devise_mailer/#{key}", :body => assigns
      end
    end

    # Setup subject namespaced by model. It means you're able to setup your
    # messages using specific resource scope, or provide a default one.
    # Example (i18n locale file):
    #<commit_msg>Devise.mailer_sender accepts a proc too, passing mapping. Useful if sender e-mail should differ for different devise scopes or current locale.<commit_after>class DeviseMailer < ::ActionMailer::Base

  # Deliver confirmation instructions when the user is created or its email is
  # updated, and also when confirmation is manually requested
  def confirmation_instructions(record)
    setup_mail(record, :confirmation_instructions)
  end

  # Deliver reset password instructions when manually requested
  def reset_password_instructions(record)
    setup_mail(record, :reset_password_instructions)
  end

  private

    # Configure default email options
    def setup_mail(record, key)
      mapping = Devise::Mapping.find_by_class(record.class)
      raise "Invalid devise resource #{record}" unless mapping

      subject      translate(mapping, key)
      from         Devise.mailer_sender.is_a?(Proc) ? Devise.mailer_sender.call(mapping.name) : Devise.mailer_sender
      recipients   record.email
      sent_on      Time.now
      content_type 'text/html'
      body         render_with_scope(key, mapping, mapping.name => record, :resource => record)
    end

    def render_with_scope(key, mapping, assigns)
      if Devise.scoped_views
        begin
          render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
        rescue ActionView::MissingTemplate
          render :file => "devise_mailer/#{key}", :body => assigns
        end
      else
        render :file => "devise_mailer/#{key}", :body => assigns
      end
    end

    # Setup subject namespaced by model. It means you're able to setup your
    # messages using specific resource scope, or provide a default one.
    # Example (i18n locale file):
    #
{'fraction_non_alphanumeric': 0.07962172056131787, 'fraction_numerical': 0.0012202562538133007, 'mean_word_length': 3.1877394636015324, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5972547', 'n_tokens_mistral': 907, 'n_tokens_neox': 880, 'n_words': 281}