Class: TestTrack::VaryDsl

Inherits:
Object
  • Object
show all
Includes:
RequiredOptions
Defined in:
app/models/test_track/vary_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ VaryDsl

Returns a new instance of VaryDsl.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/test_track/vary_dsl.rb', line 7

def initialize(opts = {})
  @assignment = require_option!(opts, :assignment)
  @context = require_option!(opts, :context)
  @split_registry = require_option!(opts, :split_registry)
  raise ArgumentError, "unknown opts: #{opts.keys.to_sentence}" if opts.present?

  if @split_registry.loaded? && !split
    raise ArgumentError, "unknown split: #{split_name}." \
      "#{' You may need to run rake test_track:schema:load.' if Rails.env.development?}"
  end
end

Instance Attribute Details

#default_variantObject (readonly)

Returns the value of attribute default_variant.



4
5
6
# File 'app/models/test_track/vary_dsl.rb', line 4

def default_variant
  @default_variant
end

#defaultedObject (readonly) Also known as: defaulted?

Returns the value of attribute defaulted.



4
5
6
# File 'app/models/test_track/vary_dsl.rb', line 4

def defaulted
  @defaulted
end

Instance Method Details

#default(variant, &block) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
# File 'app/models/test_track/vary_dsl.rb', line 27

def default(variant, &block)
  raise ArgumentError, "cannot provide more than one `default`" unless default_variant.nil?

  @default_variant = assign_behavior_to_variant(variant, block)
end

#when(*variants, &block) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'app/models/test_track/vary_dsl.rb', line 19

def when(*variants, &block)
  raise ArgumentError, "must provide at least one variant" if variants.blank?

  variants.each do |variant|
    assign_behavior_to_variant(variant, block)
  end
end