class Vanity::Playground
Playground
catalogs all your experiments. For configuration please see Vanity::Configuration
, for connection management, please see Vanity::Connection
.
Attributes
Returns hash of experiments (key is experiment id). This creates the Experiment
and persists it to the datastore.
@see Vanity::Experiment
Returns hash of metrics (key is metric id).
@see Vanity::Metric
@since 1.1.0 @deprecated
Public Class Methods
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
@deprecated @see Configuration#add_participant_route
# File lib/vanity/playground.rb, line 77 def add_participant_path Vanity.configuration.add_participant_route end
@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
@since 1.4.0 @deprecated @see Configuration#collecting
# File lib/vanity/playground.rb, line 137 def collecting=(enabled) Vanity.configuration.collecting = enabled end
@since 1.4.0 @deprecated @see Configuration#collecting
# File lib/vanity/playground.rb, line 130 def collecting? Vanity.configuration.collecting end
@since 1.4.0 @deprecated @see Vanity.connection
# File lib/vanity/playground.rb, line 221 def connected? Vanity.connection.connected? end
@since 1.4.0 @deprecated @see Vanity.connection
# File lib/vanity/playground.rb, line 214 def connection Vanity.connection.adapter end
@deprecated @see Configuration#templates_path
# File lib/vanity/playground.rb, line 55 def custom_templates_path Vanity.configuration.templates_path end
# File lib/vanity/playground.rb, line 59 def custom_templates_path=(path) Vanity.configuration.templates_path = path end
@since 1.4.0 @deprecated @see Vanity.disconnect!
# File lib/vanity/playground.rb, line 228 def disconnect! Vanity.disconnect! end
@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
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
# File lib/vanity/playground.rb, line 153 def experiments_persisted? experiments.keys.all? { |id| connection.experiment_persisted?(id) } end
@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
@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
@deprecated @see Vanity#load!
# File lib/vanity/playground.rb, line 149 def load! Vanity.load! end
@deprecated @see Configuration#experiments_path
# File lib/vanity/playground.rb, line 31 def load_path Vanity.configuration.experiments_path end
@deprecated @see Configuration#experiments_path
# File lib/vanity/playground.rb, line 37 def load_path=(path) Vanity.configuration.experiments_path = path end
@deprecated @see Configuration#logger
# File lib/vanity/playground.rb, line 43 def logger Vanity.configuration.logger end
@deprecated @see Configuration#logger
# File lib/vanity/playground.rb, line 49 def logger=(logger) Vanity.configuration.logger = logger end
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
@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
@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
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
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
@deprecated @see Vanity#reload!
# File lib/vanity/playground.rb, line 143 def reload! Vanity.reload! end
@since 1.9.0 @deprecated @see Configuration#request_filter
# File lib/vanity/playground.rb, line 117 def request_filter Vanity.configuration.request_filter end
@deprecated @see Configuration#request_filter=
# File lib/vanity/playground.rb, line 123 def request_filter=(filter) Vanity.configuration.request_filter = filter end
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
@deprecated @see Configuration#use_js
# File lib/vanity/playground.rb, line 65 def use_js! Vanity.configuration.use_js = true end
@deprecated @see Configuration#use_js
# File lib/vanity/playground.rb, line 71 def using_js? Vanity.configuration.use_js end
Private Instance Methods
# 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
# 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