Sha256: d54809a373e92a9af62dc52bbf96e77ac62cd5ced0a693d8d066297b608ddce1

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 Bytes

Contents

module Split
  module Helper
    def ab_test(experiment_name, *alternatives)
      experiment = Split::Experiment.find_or_create(experiment_name, *alternatives)
      return experiment.winner.name if experiment.winner

      if ab_user[experiment_name]
        return ab_user[experiment_name]
      else
        alternative = experiment.next_alternative
        alternative.increment_participation
        ab_user[experiment_name] = alternative.name
        return alternative.name
      end
    end

    def finished(experiment_name)
      alternative_name = ab_user[experiment_name]
      alternative = Split::Alternative.find(alternative_name, experiment_name)
      alternative.increment_completion
      session[:split].delete(experiment_name)
    end

    def ab_user
      session[:split] ||= {}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
split-0.1.1 lib/split/helper.rb
split-0.1.0 lib/split/helper.rb