<commit_before>class AsciicastsController < ApplicationController
  PER_PAGE = 15

  before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
  before_filter :count_view, :only => [:show]
  before_filter :ensure_authenticated!, :only => [:edit, :update, :destroy]
  before_filter :ensure_owner!, :only => [:edit, :update, :destroy]

  respond_to :html, :json

  def index
    collection = Asciicast.
      newest.
      includes(:user).
      page(params[:page]).
      per(PER_PAGE)

    @category_name = "All Asciicasts"
    @current_category = :all
    @asciicasts = AsciicastDecorator.decorate(collection)
  end

  def popular
    collection = Asciicast.
      popular.
      includes(:user).
      page(params[:page]).
      per(PER_PAGE)

    @category_name = "Popular Asciicasts"
    @current_category = :popular
    @asciicasts = AsciicastDecorator.decorate(collection)

    render :index
  end

  def show
    @asciicast = AsciicastDecorator.new(@asciicast)
    @asciicast_author = UserDecorator.new(@asciicast.user)
    @title = @asciicast.smart_title
    respond_with @asciicast
  end

  def edit
  end

  def update
    @asciicast.update_attributes(params[:asciicast])
    redirect_to asciicast_path(@asciicast),
                :notice => 'Asciicast was updated.'
  end

  def destroy
    if @asciicast.destroy
      redirect_to profile_path(current_user),
                  :notice => 'Asciicast was deleted.'
    else
      redirect_to asciicast_path(@asciicast),
                  :alert => "Oops, we couldn't remove this asciicast. " \<commit_msg>HTTP caching for asciicast json data<commit_after>class AsciicastsController < ApplicationController
  PER_PAGE = 15

  before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
  before_filter :count_view, :only => [:show]
  before_filter :ensure_authenticated!, :only => [:edit, :update, :destroy]
  before_filter :ensure_owner!, :only => [:edit, :update, :destroy]

  respond_to :html, :json

  def index
    collection = Asciicast.
      newest.
      includes(:user).
      page(params[:page]).
      per(PER_PAGE)

    @category_name = "All Asciicasts"
    @current_category = :all
    @asciicasts = AsciicastDecorator.decorate(collection)
  end

  def popular
    collection = Asciicast.
      popular.
      includes(:user).
      page(params[:page]).
      per(PER_PAGE)

    @category_name = "Popular Asciicasts"
    @current_category = :popular
    @asciicasts = AsciicastDecorator.decorate(collection)

    render :index
  end

  def show
    @asciicast = AsciicastDecorator.new(@asciicast)

    respond_to do |format|
      format.html do
        @asciicast_author = UserDecorator.new(@asciicast.user)
        @title = @asciicast.smart_title
        respond_with @asciicast
      end

      format.json do
        if stale? @asciicast
          respond_with @asciicast
        end
      end
    end

  end

  def edit
  end

  def update
    @asciicast.update_attributes(params[:asciicast])
    redirect_to asciicast_path(@asciicast),
                :notice => 'Asciicast was updated.'
  end

  def destroy
    if @asciicast.destroy
      redirect_to profile_path(current_user),
                  :notice => 'Asciicast was deleted.'
    else
      redirect_to asciicast_path(@asciicast),
                  :alert => "Oops, we couldn't remove this asciicast. " \
{'fraction_non_alphanumeric': 0.1029673590504451, 'fraction_numerical': 0.0011869436201780415, 'mean_word_length': 2.9799291617473433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6527018', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1110, 'n_words': 239}