class Vanity::Playground

Playground catalogs all your experiments. For configuration please see Vanity::Configuration, for connection management, please see Vanity::Connection.

Attributes

experiments[R]

Returns hash of experiments (key is experiment id). This creates the Experiment and persists it to the datastore.

@see Vanity::Experiment

metrics[R]

Returns hash of metrics (key is metric id).

@see Vanity::Metric @since 1.1.0 @deprecated

Public Class Methods

new() click to toggle source

Created new Playground. Unless you need to, use the global Vanity.playground.

# File lib/vanity/playground.rb, line 23
def initialize
  @loading = []
  set_metrics
  set_experiments
end

Public Instance Methods

add_participant_path() click to toggle source

@deprecated @see Configuration#add_participant_route

# File lib/vanity/playground.rb, line 77
def add_participant_path
  Vanity.configuration.add_participant_route
end
add_participant_path=(path) click to toggle source

@deprecated @see Configuration#add_participant_route=

# File lib/vanity/playground.rb, line 83
def add_participant_path=(path)
  Vanity.configuration.add_participant_route=path
end
collecting=(enabled) click to toggle source

@since 1.4.0 @deprecated @see Configuration#collecting

# File lib/vanity/playground.rb, line 137
def collecting=(enabled)
  Vanity.configuration.collecting = enabled
end
collecting?() click to toggle source

@since 1.4.0 @deprecated @see Configuration#collecting

# File lib/vanity/playground.rb, line 130
def collecting?
  Vanity.configuration.collecting
end
connected?() click to toggle source

@since 1.4.0 @deprecated @see Vanity.connection

# File lib/vanity/playground.rb, line 221
def connected?
  Vanity.connection.connected?
end
connection() click to toggle source

@since 1.4.0 @deprecated @see Vanity.connection

# File lib/vanity/playground.rb, line 214
def connection
  Vanity.connection.adapter
end
custom_templates_path() click to toggle source

@deprecated @see Configuration#templates_path

# File lib/vanity/playground.rb, line 55
def custom_templates_path
  Vanity.configuration.templates_path
end
custom_templates_path=(path) click to toggle source
# File lib/vanity/playground.rb, line 59
def custom_templates_path=(path)
  Vanity.configuration.templates_path = path
end
disconnect!() click to toggle source

@since 1.4.0 @deprecated @see Vanity.disconnect!

# File lib/vanity/playground.rb, line 228
def disconnect!
  Vanity.disconnect!
end
establish_connection(spec=nil) click to toggle source

@since 1.4.0 @deprecated @see Vanity::Connection

# File lib/vanity/playground.rb, line 206
def establish_connection(spec=nil)
  disconnect!
  Vanity.connect!(spec)
end
experiment(name) click to toggle source

Returns the experiment. You may not have guessed, but this method raises an exception if it cannot load the experiment's definition.

@see Vanity::Experiment @deprecated

# File lib/vanity/playground.rb, line 180
def experiment(name)
  id = name.to_s.downcase.gsub(/\W/, "_").to_sym
  Vanity.logger.warn("Deprecated: Please call experiment method with experiment identifier (a Ruby symbol)") unless id == name
  experiments[id.to_sym] or raise NoExperimentError, "No experiment #{id}"
end
experiments_persisted?() click to toggle source
# File lib/vanity/playground.rb, line 153
def experiments_persisted?
  experiments.keys.all? { |id| connection.experiment_persisted?(id) }
end
failover_on_datastore_error!() click to toggle source

@since 1.9.0 @deprecated @see Configuration#failover_on_datastore_error

# File lib/vanity/playground.rb, line 90
def failover_on_datastore_error!
  Vanity.configuration.failover_on_datastore_error = true
end
failover_on_datastore_error?() click to toggle source

@since 1.9.0 @deprecated @see Configuration#failover_on_datastore_error

# File lib/vanity/playground.rb, line 97
def failover_on_datastore_error?
  Vanity.configuration.failover_on_datastore_error
end
load!() click to toggle source

@deprecated @see Vanity#load!

# File lib/vanity/playground.rb, line 149
def load!
  Vanity.load!
end
load_path() click to toggle source

@deprecated @see Configuration#experiments_path

# File lib/vanity/playground.rb, line 31
def load_path
  Vanity.configuration.experiments_path
end
load_path=(path) click to toggle source

@deprecated @see Configuration#experiments_path

# File lib/vanity/playground.rb, line 37
def load_path=(path)
  Vanity.configuration.experiments_path = path
end
logger() click to toggle source

@deprecated @see Configuration#logger

# File lib/vanity/playground.rb, line 43
def logger
  Vanity.configuration.logger
end
logger=(logger) click to toggle source

@deprecated @see Configuration#logger

# File lib/vanity/playground.rb, line 49
def logger=(logger)
  Vanity.configuration.logger = logger
end
metric(id) click to toggle source

Returns a metric (raises NameError if no metric with that identifier).

@see Vanity::Metric @since 1.1.0

# File lib/vanity/playground.rb, line 161
def metric(id)
  metrics[id.to_sym] or raise NameError, "No metric #{id}"
end
on_datastore_error() click to toggle source

@since 1.9.0 @deprecated @see Configuration#on_datastore_error

# File lib/vanity/playground.rb, line 104
def on_datastore_error
  Vanity.configuration.on_datastore_error
end
on_datastore_error=(closure) click to toggle source

@deprecated @see Configuration#on_datastore_error

# File lib/vanity/playground.rb, line 110
def on_datastore_error=(closure)
  Vanity.configuration.on_datastore_error = closure
end
participant_info(participant_id) click to toggle source

Returns an array of all experiments this participant is involved in, with their assignment.

This is done as an array of arrays [[<experiment_1>, <assignment_1>], [<experiment_2>, <assignment_2>]], sorted by experiment name, so that it will give a consistent string
when converted to_s (so could be used for caching, for example)
# File lib/vanity/playground.rb, line 192
def participant_info(participant_id)
  participant_array = []
  experiments.values.sort_by(&:name).each do |e|
    index = connection.ab_assigned(e.id, participant_id)
    if index
      participant_array << [e, e.alternatives[index.to_i]]
    end
  end
  participant_array
end
reconnect!() click to toggle source

Closes the current connection and establishes a new one.

@since 1.3.0 @deprecated

# File lib/vanity/playground.rb, line 236
def reconnect!
  Vanity.reconnect!
end
reload!() click to toggle source

@deprecated @see Vanity#reload!

# File lib/vanity/playground.rb, line 143
def reload!
  Vanity.reload!
end
request_filter() click to toggle source

@since 1.9.0 @deprecated @see Configuration#request_filter

# File lib/vanity/playground.rb, line 117
def request_filter
  Vanity.configuration.request_filter
end
request_filter=(filter) click to toggle source

@deprecated @see Configuration#request_filter=

# File lib/vanity/playground.rb, line 123
def request_filter=(filter)
  Vanity.configuration.request_filter = filter
end
track!(id, count = 1) click to toggle source

Tracks an action associated with a metric.

@example

Vanity.playground.track! :uploaded_video

@since 1.1.0

# File lib/vanity/playground.rb, line 171
def track!(id, count = 1)
  metric(id).track!(count)
end
use_js!() click to toggle source

@deprecated @see Configuration#use_js

# File lib/vanity/playground.rb, line 65
def use_js!
  Vanity.configuration.use_js = true
end
using_js?() click to toggle source

@deprecated @see Configuration#use_js

# File lib/vanity/playground.rb, line 71
def using_js?
  Vanity.configuration.use_js
end

Private Instance Methods

set_experiments() click to toggle source
# File lib/vanity/playground.rb, line 242
def set_experiments
  @experiments = {}

  Vanity.logger.info("Vanity: loading experiments from #{Vanity.configuration.experiments_path}")

  Dir[File.join(Vanity.configuration.experiments_path, "*.rb")].each do |file|
    Experiment::Base.load(self, @loading, file)
  end
end
set_metrics() click to toggle source
# File lib/vanity/playground.rb, line 252
def set_metrics
  @metrics = {}

  Vanity.logger.info("Vanity: loading metrics from #{Vanity.configuration.experiments_path}/metrics")

  Dir[File.join(Vanity.configuration.experiments_path, "metrics/*.rb")].each do |file|
    Metric.load(self, @loading, file)
  end
end