<commit_before># module that provides model filtering behavior
module ModelFilter

  # Engine inclusion for automatic rails ../app/ loading
  class Engine < Rails::Engine
  end

  module Base
    def self.included(base)
      base.extend Config
    end

    module Config
      def acts_as_filterable
        extend ClassMethods
        yield self if block_given?
        privatize_config
      end
    end
  end

  module ClassMethods
    extend self

    # filters placement in params (e.g. params[:filters]
    DEFAULT_FILTERS_PLACEMENT = :filters

    DEFAULT_COMPARISON_SYMBOLS = {
      '='  => :eq,
      '<'  => :lt,
      '>'  => :gt,
      '<=' => :lteq,
      '>=' => :gteq,
      '!=' => :not_eq
    }

    # Usage:
    #   MyModel.filtered({:id => 3, :col2 => 1..9, :col2_compar => :not_in})
    # method expects that comparison symbols param names composed of column
    # name and '_compar' suffix ('id - id_compar')
    #
    # Arguments hash can contain <tt><b>:ignore_blank_values => true (or false)</b></tt>
    # that overrides global settings once.
    def filtered(filters = {})
      to_filter = suitable_keys(filters)
      to_filter.empty? ? scoped : to_filter.inject(self){|injected, field|
        injected.with_value_of(field, filters[field], filters["#{field}_compar".to_sym])
      }
    end

    # Usage:
    #   MyModel.with_value_of(:id, 3..5)
    #   MyModel.with_value_of(:id, 3, :eq)
    #   MyModel.with_value_of(:id, [3,5,12], :not_in)
    def with_value_of(field, wanted_value, compar_sym = nil)
      compar_sym ||= wanted_value.is_a?(Array) || wanted_value.is_a?(Range) ? :in : :eq
      @areltable ||= arel_table
      mapping = filter_mappings[field]
      if mapping
        send(mapping, compar_sym, wanted_value)
      else
        where(@areltable[field].send(compar_sym, wanted_value))
      end
    end

    # for use in views
    #
    # Usage:
    #   <%= select_tag 'id_compar', options_for_select(MyModel.comparison_symbols) %>
    def comparison_symbols<commit_msg>fixed mistake in method call<commit_after># module that provides model filtering behavior
module ModelFilter

  # Engine inclusion for automatic rails ../app/ loading
  class Engine < Rails::Engine
  end

  module Base
    def self.included(base)
      base.extend Config
    end

    module Config
      def acts_as_filterable
        extend ClassMethods
        yield self if block_given?
        privatize_config
      end
    end
  end

  module ClassMethods
    extend self

    # filters placement in params (e.g. params[:filters]
    DEFAULT_FILTERS_PLACEMENT = :filters

    DEFAULT_COMPARISON_SYMBOLS = {
      '='  => :eq,
      '<'  => :lt,
      '>'  => :gt,
      '<=' => :lteq,
      '>=' => :gteq,
      '!=' => :not_eq
    }

    # Usage:
    #   MyModel.filtered({:id => 3, :col2 => 1..9, :col2_compar => :not_in})
    # method expects that comparison symbols param names composed of column
    # name and '_compar' suffix ('id - id_compar')
    #
    # Arguments hash can contain <tt><b>:ignore_blank_values => true (or false)</b></tt>
    # that overrides global settings once.
    def filtered(filters = {})
      to_filter = suitable_keys(filters)
      to_filter.empty? ? scoped : to_filter.inject(self){|injected, field|
        injected.with_value_of(field, filters[field], filters["#{field}_compar".to_sym])
      }
    end

    # Usage:
    #   MyModel.with_value_of(:id, 3..5)
    #   MyModel.with_value_of(:id, 3, :eq)
    #   MyModel.with_value_of(:id, [3,5,12], :not_in)
    def with_value_of(field, wanted_value, compar_sym = nil)
      compar_sym ||= wanted_value.is_a?(Array) || wanted_value.is_a?(Range) ? :in : :eq
      @areltable ||= arel_table
      mapping = filter_mappings[field]
      if mapping
        send(mapping, wanted_value, compar_sym)
      else
        where(@areltable[field].send(compar_sym, wanted_value))
      end
    end

    # for use in views
    #
    # Usage:
    #   <%= select_tag 'id_compar', options_for_select(MyModel.comparison_symbols) %>
    def comparison_symbols
{'fraction_non_alphanumeric': 0.12139156180606958, 'fraction_numerical': 0.005921539600296077, 'mean_word_length': 2.750231267345051, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, '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': '1505368', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1330, 'n_words': 305}