<commit_before>module Melitta::Adapters

  module Controller

    def filter selector, resource=selector, &block
      selector = infer_selector(selector)
      resource = infer_resource_name(resource)

      filter = Melitta::FilterDsl.evaluate(&block)
      class_variable_set(:"@@#{selector}_filter", filter)

      class_eval <<-RUBY
         def #{selector}_params
          @#{selector}_params ||= begin
            filter = self.class.class_variable_get(:"@@#{selector}_filter")
            filter.run(params.fetch(:"#{selector}", {}))
          end
        end
        protected :"#{selector}_params"
      RUBY

      class_eval <<-RUBY
         def #{selector}_form
          @#{selector}_form ||= begin
            Melitta::Bridges::ActiveModel.new(#{resource}).form(#{selector}_params)
          end
        end
        protected :"#{selector}_form"
      RUBY<commit_msg>updated controller filter interface to support several forms per controller<commit_after>module Melitta::Adapters

  module Controller

    def filter selector, resource=selector, prefix=nil, &block
      selector = infer_selector(selector)
      resource = infer_resource_name(resource)
      prefix   = prefix || selector

      filter = Melitta::FilterDsl.evaluate(&block)
      class_variable_set(:"@@#{prefix}_filter", filter)

      class_eval <<-RUBY
         def #{prefix}_params
          @#{prefix}_params ||= begin
            filter = self.class.class_variable_get(:"@@#{prefix}_filter")
            filter.run(params.fetch(:"#{selector}", {}))
          end
        end
        protected :"#{prefix}_params"
      RUBY

      class_eval <<-RUBY
         def #{prefix}_form
          @#{prefix}_form ||= begin
            Melitta::Bridges::ActiveModel.new(#{resource}).form(#{prefix}_params)
          end
        end
        protected :"#{prefix}_form"
      RUBY
{'fraction_non_alphanumeric': 0.12634408602150538, 'fraction_numerical': 0.0, 'mean_word_length': 2.649019607843137, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1667445', 'n_tokens_mistral': 518, 'n_tokens_neox': 507, 'n_words': 98}