Sha256: a38547d86b132407b100b512b61a501ee9b23944de7ae42e1f4d8b3cb77976ae

Contents?: true

Size: 1.11 KB

Versions: 24

Compression:

Stored size: 1.11 KB

Contents

module Vanity
  module Experiment
    # These methods are available from experiment definitions (files located in
    # the experiments directory, automatically loaded by Vanity). Use these
    # methods to define your experiments, for example:
    #   ab_test "New Banner" do
    #     alternatives :red, :green, :blue
    #     metrics :signup
    #   end
    module Definition

      attr_reader :playground

      # Defines a new experiment, given the experiment's name, type and
      # definition block.
      def define(name, type, options = nil, &block)
        fail "Experiment #{@experiment_id} already defined in playground" if playground.experiments[@experiment_id]
        klass = Experiment.const_get(type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
        experiment = klass.new(playground, @experiment_id, name, options)
        experiment.instance_eval &block
        experiment.save
        playground.experiments[@experiment_id] = experiment
      end

      def new_binding(playground, id)
        @playground, @experiment_id = playground, id
        binding
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
vanity-2.2.4 lib/vanity/experiment/definition.rb
vanity-2.2.3 lib/vanity/experiment/definition.rb
vanity-2.2.2 lib/vanity/experiment/definition.rb
vanity-2.2.1 lib/vanity/experiment/definition.rb
vanity-2.2.0 lib/vanity/experiment/definition.rb
vanity-2.1.2 lib/vanity/experiment/definition.rb
vanity-2.1.1 lib/vanity/experiment/definition.rb
vanity-2.1.0 lib/vanity/experiment/definition.rb
vanity-2.0.1 lib/vanity/experiment/definition.rb
vanity-2.0.0 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta9 lib/vanity/experiment/definition.rb
vanity-1.9.3 lib/vanity/experiment/definition.rb
vanity-1.9.2 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta8 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta7 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta6 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta5 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta4 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta3 lib/vanity/experiment/definition.rb
vanity-2.0.0.beta2 lib/vanity/experiment/definition.rb