<commit_before># frozen_string_literal: true

class ManeuversController < ApplicationController
  before_action :find_maneuver, only: %i[next_participant previous_participant]

  def index
    @page_title = 'Select a Maneuver'
    @maneuvers = Maneuver.order :sequence_number
  end

  def next_participant
    participant = @maneuver.next_participant(params[:relative_to])
    if participant.present?
      if participant.has_completed? @maneuver
        record = ManeuverParticipant.find_by maneuver: @maneuver,
                                             participant: participant
        redirect_to record
      else
        redirect_to(
          new_maneuver_participant_path maneuver: @maneuver.name,
                                        participant: participant.number
        )
      end
    else redirect_to maneuvers_path,
                     notice: 'There are no more participants in the queue for
                              this maneuver.'
    end
  end

  def previous_participant
    participant = @maneuver.previous_participant(params[:relative_to])
    if participant.present?
      record = ManeuverParticipant.find_by maneuver: @maneuver,
                                           participant: participant
    else
      flash[:notice] =
        'This is the first participant who completed this maneuver.'
      record = ManeuverParticipant.find_by maneuver: @maneuver,
                                           participant: params[:relative_to]
    end
    redirect_to record
  end

  private

  def find_maneuver
    @maneuver = Maneuver.find_by id: params.require(:id)
  end
end<commit_msg>Don't know why the specs didn't catch this before<commit_after># frozen_string_literal: true

class ManeuversController < ApplicationController
  before_action :find_maneuver, only: %i[next_participant previous_participant]

  def index
    @page_title = 'Select a Maneuver'
    @maneuvers = Maneuver.order :sequence_number
  end

  def next_participant
    participant = @maneuver.next_participant(params[:relative_to])
    if participant.present?
      if participant.has_completed? @maneuver
        record = ManeuverParticipant.find_by maneuver: @maneuver,
                                             participant: participant
        redirect_to record
      else
        redirect_to(
          new_maneuver_participant_path maneuver: @maneuver.name,
                                        participant: participant.number
        )
      end
    else redirect_to maneuvers_path,
                     notice: 'There are no more participants in the queue for
                              this maneuver.'
    end
  end

  def previous_participant
    participant = @maneuver.previous_participant(params[:relative_to])
    if participant.blank?
      participant = Participant.find_by(number: params[:relative_to])
      flash[:notice] =
        'This is the first participant who completed this maneuver.'
    end
    redirect_to ManeuverParticipant.find_by maneuver: @maneuver,
                                            participant: participant
  end

  private

  def find_maneuver
    @maneuver = Maneuver.find_by id: params.require(:id)
  end
end
{'fraction_non_alphanumeric': 0.05787983642654923, 'fraction_numerical': 0.0, 'mean_word_length': 2.264887063655031, 'pattern_counts': {'":': 0, '<': 5, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809351', 'n_tokens_mistral': 876, 'n_tokens_neox': 820, 'n_words': 211}