<commit_before>require "calagator/duplicate_checking/controller_actions"

module Calagator

class VenuesController < Calagator::ApplicationController
  # Provides #duplicates and #squash_many_duplicates
  include DuplicateChecking::ControllerActions
  require_admin only: [:duplicates, :squash_many_duplicates]

  def venue
    @venue ||= params[:id] ? Venue.find(params[:id]) : Venue.new
  end


  # GET /venues
  def index
    @search = Venue::Search.new(params.permit!)
    @venues = @search.venues

    flash[:failure] = @search.failure_message
    return redirect_to venues_path if @search.hard_failure?
    render_venues @venues
  end

  def render_venues venues
    respond_to do |format|
      format.html # index.html.erb
      format.kml  # index.kml.erb
      format.xml  { render xml:  venues }
      format.json { render json: venues, callback: params[:callback] }
      format.js   { render json: venues, callback: params[:callback] }
    end
  end
  private :render_venues


  # GET /autocomplete via AJAX
  def autocomplete
    @venues = Venue
      .non_duplicates
      .in_business
      .where(["LOWER(title) LIKE ?", "%#{params[:term]}%".downcase])
      .order('LOWER(title)')

    render json: @venues, callback: params[:callback]
  end


  # GET /venues/map
  def map
    @venues = Venue.non_duplicates.in_business
  end


  # GET /venues/1
  before_action :show_all_if_not_found, :ensure_progenitor, only: :show

  def show_all_if_not_found
    venue
  rescue ActiveRecord::RecordNotFound => e
    flash[:failure] = e.to_s
    redirect_to venues_path
    false
  end
  private :show_all_if_not_found

  def ensure_progenitor
    return unless venue.duplicate?
    redirect_to venue.progenitor
    false
  end
  private :ensure_progenitor

  def show
    respond_to do |format|
      format.html
      format.xml  { render xml: venue }
      format.json { render json: venue, callback: params[:callback] }
      format.ics  { render ics: venue.events.order("start_time ASC") }
    end
  end


  # GET /venues/new
  def new
    venue
    render layout: params[:layout] != "false"
  end


  # GET /venues/1/edit
  def edit
    venue
  end


  # POST /venues, # PUT /venues/1
  def create
    CreateOrUpdate.new(self).call
  end
  alias_method :update, :create
<commit_msg>extract Show action class.<commit_after>require "calagator/duplicate_checking/controller_actions"

module Calagator

class VenuesController < Calagator::ApplicationController
  # Provides #duplicates and #squash_many_duplicates
  include DuplicateChecking::ControllerActions
  require_admin only: [:duplicates, :squash_many_duplicates]

  def venue
    @venue ||= params[:id] ? Venue.find(params[:id]) : Venue.new
  end


  # GET /venues
  def index
    @search = Venue::Search.new(params.permit!)
    @venues = @search.venues

    flash[:failure] = @search.failure_message
    return redirect_to venues_path if @search.hard_failure?
    render_venues @venues
  end

  def render_venues venues
    respond_to do |format|
      format.html # index.html.erb
      format.kml  # index.kml.erb
      format.xml  { render xml:  venues }
      format.json { render json: venues, callback: params[:callback] }
      format.js   { render json: venues, callback: params[:callback] }
    end
  end
  private :render_venues


  # GET /autocomplete via AJAX
  def autocomplete
    @venues = Venue
      .non_duplicates
      .in_business
      .where(["LOWER(title) LIKE ?", "%#{params[:term]}%".downcase])
      .order('LOWER(title)')

    render json: @venues, callback: params[:callback]
  end


  # GET /venues/map
  def map
    @venues = Venue.non_duplicates.in_business
  end


  # GET /venues/1
  def show
    Show.new(self).call
  end

  class Show < SimpleDelegator
    def call
      return if show_all_if_not_found
      return if ensure_progenitor
      respond_to do |format|
        format.html
        format.xml  { render xml: venue }
        format.json { render json: venue, callback: params[:callback] }
        format.ics  { render ics: venue.events.order("start_time ASC") }
      end
    end

    private

    def show_all_if_not_found
      return if venue
    rescue ActiveRecord::RecordNotFound => e
      flash[:failure] = e.to_s
      redirect_to venues_path
    end

    def ensure_progenitor
      return unless venue.duplicate?
      redirect_to venue.progenitor
    end
  end


  # GET /venues/new
  def new
    venue
    render layout: params[:layout] != "false"
  end


  # GET /venues/1/edit
  def edit
    venue
  end


  # POST /venues, # PUT /venues/1
  def create
    CreateOrUpdate.new(self).call
  end
  alias_method :update, :create

{'fraction_non_alphanumeric': 0.09450171821305842, 'fraction_numerical': 0.001288659793814433, 'mean_word_length': 3.0181190681622088, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '7580801', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1523, 'n_words': 371}