<commit_before>require 'rake'
require 'rake/tasklib'

module Embarista
  class SetCurrentIndexTask < ::Rake::TaskLib
    attr_accessor :name, :app, :redis

    def initialize(name = :set_current_index)
      @name = name

      yield self if block_given?

      @redis ||= Redis.client

      raise 'app must be set' unless @app
      define
    end

    private
    def define
      set_current_task = task name, :manifest_id do |t, args|
        manifest_id = args[:manifest_id] || App.env.to_s

        puts "redis.set('#{app}:index:current', '#{manifest_id}')"
        redis.set("#{app}:index:current", manifest_id)
      end
      set_current_task.add_description "Activates a manifest in the given #{App.env_var}"
    end
  end
end<commit_msg>Add support for setting redis keys besides "index". To be used for A/B testing different branches.<commit_after>require 'rake'
require 'rake/tasklib'

module Embarista
  class SetCurrentIndexTask < ::Rake::TaskLib
    attr_accessor :name, :app, :key, :redis

    def initialize(name = :set_current_index, key = 'index')
      @name = name
      @key = key

      yield self if block_given?

      @redis ||= Redis.client

      raise 'app must be set' unless @app
      define
    end

    private
    def define
      set_current_task = task(name, :manifest_id) do |t, args|
        manifest_id = args[:manifest_id] || App.env.to_s

        puts "redis.set('#{app}:#{key}:current', '#{manifest_id}')"
        redis.set("#{app}:#{key}:current", manifest_id)
      end
      set_current_task.add_description "Activates a manifest in the given #{App.env_var}"
    end
  end
end
{'fraction_non_alphanumeric': 0.11514778325123153, 'fraction_numerical': 0.0, 'mean_word_length': 3.072681704260652, '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': '4925899', 'n_tokens_mistral': 539, 'n_tokens_neox': 522, 'n_words': 144}