Sha256: f03551d5401111029d204b052140b39d536d9e2eb68dd91a7a161cbda7c41fac

Contents?: true

Size: 1.64 KB

Versions: 22

Compression:

Stored size: 1.64 KB

Contents

class TestTrack::ABConfiguration
  include TestTrack::RequiredOptions

  def initialize(opts)
    @split_name = require_option!(opts, :split_name).to_s
    true_variant = require_option!(opts, :true_variant, allow_nil: true)
    @split_registry = require_option!(opts, :split_registry, allow_nil: true)
    raise ArgumentError, "unknown opts: #{opts.keys.to_sentence}" if opts.present?

    @true_variant = true_variant.to_s if true_variant

    raise ArgumentError, unknown_split_error_message if @split_registry && !split
  end

  def variants
    @variants ||= build_variant_hash
  end

  private

  def build_variant_hash
    notify_because_ab("configures split with more than 2 variants") if split_variants && split_variants.size > 2
    { true: true_variant, false: false_variant }
  end

  def true_variant
    @true_variant ||= true
  end

  def false_variant
    @false_variant ||= non_true_variants.present? ? non_true_variants.sort.first : false
  end

  attr_reader :split_name, :split_registry

  def unknown_split_error_message
    error_message = "unknown split: #{split_name}."
    error_message << " You may need to run rake test_track:schema:load" if Rails.env.development?
    error_message
  end

  def split
    split_registry && split_registry[split_name]
  end

  def split_variants
    @split_variants ||= split.keys if split_registry
  end

  def non_true_variants
    split_variants - [true_variant.to_s] if split_variants
  end

  def notify_because_ab(msg)
    misconfiguration_notifier.notify("A/B for \"#{split_name}\" #{msg}")
  end

  def misconfiguration_notifier
    @misconfiguration_notifier ||= TestTrack::MisconfigurationNotifier.new
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
test_track_rails_client-4.0.0.alpha7 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha6 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha5 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha4 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha3 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha2 app/models/test_track/ab_configuration.rb
test_track_rails_client-4.0.0.alpha1 app/models/test_track/ab_configuration.rb
test_track_rails_client-3.0.1 app/models/test_track/ab_configuration.rb
test_track_rails_client-3.0.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-2.0.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-1.3.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-1.2.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-1.1.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-1.0.0 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.20 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.19 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.18 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.17 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.16 app/models/test_track/ab_configuration.rb
test_track_rails_client-0.9.15 app/models/test_track/ab_configuration.rb