<commit_before>module Plugins
  class << self
    def table_name_prefix
      'plugins_'
    end

    def create_for_page(plugin, page)
      plugin = plugin.new(plugin.const_get(:DEFAULTS))
      plugin.campaign_page = page
      plugin.save
    end

    def registered
      [ Plugins::Action,
        Plugins::Thermometer ]
    end

    def data_for_view(page)
      plugins_data = Plugins.registered.inject({}) do |memo, plugin|
        record = plugin.find_by_campaign_page_id(page.id)

        if record
          memo[plugin.name.split('::').last.underscore] = record.liquid_data
          memo
        end
      end

      { 'plugins' => plugins_data }
    end
  end
end<commit_msg>Helper methods for plugin management<commit_after>module Plugins
  class << self
    def table_name_prefix
      'plugins_'
    end

    def create_for_page(plugin, page)
      plugin = plugin.new(plugin.const_get(:DEFAULTS))
      plugin.campaign_page = page
      plugin.save
    end

    def registered
      [ Plugins::Action,
        Plugins::Thermometer ]
    end

    def data_for_view(page)
      plugins_data = Plugins.registered.inject({}) do |memo, plugin|
        record = plugin.find_by_campaign_page_id(page.id)

        if record
          memo[plugin.name.split('::').last.underscore] = record.liquid_data
          memo
        end
      end

      { 'plugins' => plugins_data }
    end

    def names
      registered.map{|plugin| plugin.to_s.underscore.split('/').last }
    end

    def find_for(campaign_page_id, plugin_name)
      Plugins.const_get(plugin_name.camelize).find_by(campaign_page_id: campaign_page_id)
    end
  end
end
{'fraction_non_alphanumeric': 0.09428223844282238, 'fraction_numerical': 0.0, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4699572', 'n_tokens_mistral': 539, 'n_tokens_neox': 514, 'n_words': 100}