Sha256: 4b7a1f2df0c7bc2a47b19949b79c7f2c8b7a7fbc8f63c043696a73bc92d75d02

Contents?: true

Size: 731 Bytes

Versions: 1

Compression:

Stored size: 731 Bytes

Contents

require 'eeny-meeny/models/cookie'
require 'eeny-meeny/models/experiment'

module EenyMeeny::ExperimentHelper

  def participates_in?(experiment_id, variation_id: nil)
    experiment = EenyMeeny::Experiment.find_by_id(experiment_id)
    return unless experiment.active?
    cookie = read_cookie(EenyMeeny::Cookie.cookie_name(experiment))
    cookie[:variation] unless cookie.nil? || (variation_id.present? && variation_id != cookie[:variation].id)
  end

  def smoke_test?(smoke_test_id, version: 1)
    cookie = read_cookie(EenyMeeny::Cookie.smoke_test_name(smoke_test_id, version: version))
    cookie unless cookie.nil?
  end

  private

  def read_cookie(cookie_name)
    EenyMeeny::Cookie.read(cookies[cookie_name])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eeny-meeny-2.0.0 lib/eeny-meeny/experiment_helper.rb