Class: TestTrack::VaryDsl
- Inherits:
-
Object
- Object
- TestTrack::VaryDsl
- Includes:
- RequiredOptions
- Defined in:
- app/models/test_track/vary_dsl.rb
Instance Attribute Summary collapse
-
#default_variant ⇒ Object
readonly
Returns the value of attribute default_variant.
-
#defaulted ⇒ Object
(also: #defaulted?)
readonly
Returns the value of attribute defaulted.
Instance Method Summary collapse
- #default(variant, &block) ⇒ Object
-
#initialize(opts = {}) ⇒ VaryDsl
constructor
A new instance of VaryDsl.
- #when(*variants, &block) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ VaryDsl
Returns a new instance of VaryDsl.
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_variant ⇒ Object (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 |
#defaulted ⇒ Object (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
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
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 |