<commit_before>require_dependency "manage/application_controller"
require_dependency 'kaminari'

class Manage::ResourceController < Manage::ApplicationController
  inherit_resources

  cattr_accessor :per_page

  self.responder = Manage::Responder

  layout 'manage/application'

  respond_to :html

  helper_method :list_index_fields, :list_edit_fields, :list_search_fields, :list_action_links, :resource_actions, :collection_actions

  def end_of_association_chain
    if self.resources_configuration[:self][:search_fields].blank?
      self.class.search_fields :all
    end

    config = self.resources_configuration[:self]
    @search = config[:search].new(clean_search_params(params[:f]))

    @search.results
  end

  protected

  def clean_search_params(search_params)
    return {} unless search_params.is_a?(Hash)
    search_params = search_params.dup
    search_params.delete_if do |key, value|
      value == ''
    end
    search_params
  end

  def collection
    assocation = end_of_association_chain.page(params[:page] || 1)
    per_page ? assocation.per(per_page) : assocation
  end

  def permitted_params
    params.permit!
  end

  def self.index_fields(*fields)
    setup_fields(:index_fields, *fields)
  end
<commit_msg>add scopes to the collection<commit_after>require_dependency "manage/application_controller"
require_dependency 'kaminari'

class Manage::ResourceController < Manage::ApplicationController
  inherit_resources

  cattr_accessor :per_page

  self.responder = Manage::Responder

  layout 'manage/application'

  respond_to :html

  helper_method :list_index_fields, :list_edit_fields, :list_search_fields, :list_action_links, :resource_actions, :collection_actions

  def end_of_association_chain
    if self.resources_configuration[:self][:search_fields].blank?
      self.class.search_fields :all
    end

    config = self.resources_configuration[:self]
    @search = config[:search].new(clean_search_params(params[:f]))

    @search.results
  end

  protected

  def clean_search_params(search_params)
    return {} unless search_params.is_a?(Hash)
    search_params = search_params.dup
    search_params.delete_if do |key, value|
      value == ''
    end
    search_params
  end

  def self.collection_scope lambda
    @@collection_scope = lambda
  end

  def collection
    filtered_collection = end_of_association_chain
    if @@collection_scope
      filtered_collection = @@collection_scope.call(filtered_collection)
    end

    assocation = filtered_collection.page(params[:page] || 1)
    per_page ? assocation.per(per_page) : assocation
  end

  def permitted_params
    params.permit!
  end

  def self.index_fields(*fields)
    setup_fields(:index_fields, *fields)
  end

{'fraction_non_alphanumeric': 0.08403669724770642, 'fraction_numerical': 0.0007339449541284404, 'mean_word_length': 4.667359667359667, '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': '1681472', 'n_tokens_mistral': 858, 'n_tokens_neox': 815, 'n_words': 157}