Sha256: 9f59fb79cb588a24f5b6512cde341aff15e8f70698ae125d4324440b64c0e818

Contents?: true

Size: 681 Bytes

Versions: 8

Compression:

Stored size: 681 Bytes

Contents

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

module EenyMeeny
  class ExperimentConstraint

    def initialize(experiment_id, variation_id: nil)
      @experiment = EenyMeeny::Experiment.find_by_id(experiment_id)
      @variation_id = variation_id
    end

    def matches?(request)
      return false unless !@experiment.nil? && @experiment.active?
      participant_variation_id = EenyMeeny::Cookie.read(request.cookie_jar[EenyMeeny::Cookie.cookie_name(@experiment)])
      return false if participant_variation_id.nil? # Not participating in experiment
      (@variation_id.nil? || @variation_id.to_s == participant_variation_id)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
eeny-meeny-2.3.0 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.2.2 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.2.1 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.2.0 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.1.4 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.1.3 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.1.2 lib/eeny-meeny/routing/experiment_constraint.rb
eeny-meeny-2.1.1 lib/eeny-meeny/routing/experiment_constraint.rb