Method: Vanity::Experiment::Base#identify

Defined in:
lib/vanity/experiment/base.rb

#identify(&block) ⇒ Object

Defines how we obtain an identity for the current experiment. Usually Vanity gets the identity form a session object (see use_vanity), but there are cases where you want a particular experiment to use a different identity.

For example, if all your experiments use current_user and you need one experiment to use the current project:

ab_test "Project widget" do
  alternatives :small, :medium, :large
  identify do |controller|
    controller.project.id
  end
end


111
112
113
114
# File 'lib/vanity/experiment/base.rb', line 111

def identify(&block)
  fail "Missing block" unless block
  @identify_block = block
end