<commit_before>class BucketMakerController < ApplicationController
  include BucketMakerConcern

  def show
    if BucketMaker.buckets_configuration.has_group_in_bucket_in_series?(@series_name, @bucket_name, @group_name)
      render text: @current_user.in_bucket?(@series_name, @bucket_name, @group_name)
    else
      head :not_found
    end
  end

  def switch
    if BucketMaker.buckets_configuration.has_group_in_bucket_in_series?(@series_name, @bucket_name, @group_name)
      render text: @current_user.force_to_bucket!(@series_name, @bucket_name, @group_name)
    else
      head :not_found
    end
  end

  def randomize
    if BucketMaker.buckets_configuration.has_bucket_in_series?(@series_name, @bucket_name)
      render text: @current_user.bucketize_for_series_and_bucket!(@series_name, @bucket_name)
    else
      head :not_found
    end
  end

end<commit_msg>Refactored the controller<commit_after>class BucketMakerController < ApplicationController
  include BucketMakerConcern

  before_filter :ensure_valid_series_bucket_group, only: [:show, :switch]
  before_filter :ensure_valid_series_bucket, only: [:randomize]

  def show
    render text: @current_user.in_bucket?(@series_name, @bucket_name, @group_name)
  end

  def switch
    render text: @current_user.force_to_bucket!(@series_name, @bucket_name, @group_name)
  end

  def randomize
    render text: @current_user.bucketize_for_series_and_bucket!(@series_name, @bucket_name)
  end

  private
  def ensure_valid_series_bucket_group
    not_found unless BucketMaker.buckets_configuration.has_group_in_bucket_in_series?(@series_name, @bucket_name, @group_name)
  end

  def ensure_valid_series_bucket
    not_found unless BucketMaker.buckets_configuration.has_bucket_in_series?(@series_name, @bucket_name)
  end

  def not_found
    head :not_found
    false
  end
end
{'fraction_non_alphanumeric': 0.07262872628726287, 'fraction_numerical': 0.0, 'mean_word_length': 5.409722222222222, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138541', 'n_tokens_mistral': 628, 'n_tokens_neox': 610, 'n_words': 113}