Class: Vanity::Playground
- Inherits:
-
Object
- Object
- Vanity::Playground
- Defined in:
- lib/vanity/playground.rb
Overview
Playground catalogs all your experiments. For configuration please see Vanity::Configuration, for connection management, please see Vanity::Connection.
Instance Attribute Summary collapse
-
#experiments ⇒ Object
readonly
Returns hash of experiments (key is experiment id).
- #metrics ⇒ Object readonly deprecated Deprecated.
Instance Method Summary collapse
- #add_participant_path ⇒ Object deprecated Deprecated.
- #add_participant_path=(path) ⇒ Object deprecated Deprecated.
- #collecting=(enabled) ⇒ Object deprecated Deprecated.
- #collecting? ⇒ Boolean deprecated Deprecated.
- #connected? ⇒ Boolean deprecated Deprecated.
- #connection ⇒ Object deprecated Deprecated.
- #custom_templates_path ⇒ Object deprecated Deprecated.
- #custom_templates_path=(path) ⇒ Object
- #disconnect! ⇒ Object deprecated Deprecated.
- #establish_connection(spec = nil) ⇒ Object deprecated Deprecated.
- #experiment(name) ⇒ Object deprecated Deprecated.
- #experiments_persisted? ⇒ Boolean
- #failover_on_datastore_error! ⇒ Object deprecated Deprecated.
- #failover_on_datastore_error? ⇒ Boolean deprecated Deprecated.
-
#initialize ⇒ Playground
constructor
Created new Playground.
- #load! ⇒ Object deprecated Deprecated.
- #load_path ⇒ Object deprecated Deprecated.
- #load_path=(path) ⇒ Object deprecated Deprecated.
- #logger ⇒ Object deprecated Deprecated.
- #logger=(logger) ⇒ Object deprecated Deprecated.
-
#metric(id) ⇒ Object
Returns a metric (raises NameError if no metric with that identifier).
- #on_datastore_error ⇒ Object deprecated Deprecated.
- #on_datastore_error=(closure) ⇒ Object deprecated Deprecated.
-
#participant_info(participant_id) ⇒ Object
Returns an array of all experiments this participant is involved in, with their assignment.
- #reconnect! ⇒ Object deprecated Deprecated.
- #reload! ⇒ Object deprecated Deprecated.
- #request_filter ⇒ Object deprecated Deprecated.
- #request_filter=(filter) ⇒ Object deprecated Deprecated.
-
#track!(id, count = 1) ⇒ Object
Tracks an action associated with a metric.
- #use_js! ⇒ Object deprecated Deprecated.
- #using_js? ⇒ Boolean deprecated Deprecated.
Constructor Details
#initialize ⇒ Playground
Created new Playground. Unless you need to, use the global Vanity.playground.
23 24 25 26 27 |
# File 'lib/vanity/playground.rb', line 23 def initialize @loading = [] set_metrics set_experiments end |
Instance Attribute Details
#experiments ⇒ Object (readonly)
Returns hash of experiments (key is experiment id). This creates the Experiment and persists it to the datastore.
19 20 21 |
# File 'lib/vanity/playground.rb', line 19 def experiments @experiments end |
#metrics ⇒ Object (readonly)
Returns hash of metrics (key is metric id).
13 14 15 |
# File 'lib/vanity/playground.rb', line 13 def metrics @metrics end |
Instance Method Details
#add_participant_path ⇒ Object
77 78 79 |
# File 'lib/vanity/playground.rb', line 77 def add_participant_path Vanity.configuration.add_participant_route end |
#add_participant_path=(path) ⇒ Object
83 84 85 |
# File 'lib/vanity/playground.rb', line 83 def add_participant_path=(path) Vanity.configuration.add_participant_route = path end |
#collecting=(enabled) ⇒ Object
137 138 139 |
# File 'lib/vanity/playground.rb', line 137 def collecting=(enabled) Vanity.configuration.collecting = enabled end |
#collecting? ⇒ Boolean
130 131 132 |
# File 'lib/vanity/playground.rb', line 130 def collecting? Vanity.configuration.collecting end |
#connected? ⇒ Boolean
218 219 220 |
# File 'lib/vanity/playground.rb', line 218 def connected? Vanity.connection.connected? end |
#connection ⇒ Object
211 212 213 |
# File 'lib/vanity/playground.rb', line 211 def connection Vanity.connection.adapter end |
#custom_templates_path ⇒ Object
55 56 57 |
# File 'lib/vanity/playground.rb', line 55 def custom_templates_path Vanity.configuration.templates_path end |
#custom_templates_path=(path) ⇒ Object
59 60 61 |
# File 'lib/vanity/playground.rb', line 59 def custom_templates_path=(path) Vanity.configuration.templates_path = path end |
#disconnect! ⇒ Object
225 226 227 |
# File 'lib/vanity/playground.rb', line 225 def disconnect! Vanity.disconnect! end |
#establish_connection(spec = nil) ⇒ Object
203 204 205 206 |
# File 'lib/vanity/playground.rb', line 203 def establish_connection(spec = nil) disconnect! Vanity.connect!(spec) end |
#experiment(name) ⇒ Object
Returns the experiment. You may not have guessed, but this method raises an exception if it cannot load the experiment’s definition.
180 181 182 183 184 |
# 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? ⇒ Boolean
153 154 155 |
# File 'lib/vanity/playground.rb', line 153 def experiments_persisted? experiments.keys.all? { |id| connection.experiment_persisted?(id) } end |
#failover_on_datastore_error! ⇒ Object
90 91 92 |
# File 'lib/vanity/playground.rb', line 90 def failover_on_datastore_error! Vanity.configuration.failover_on_datastore_error = true end |
#failover_on_datastore_error? ⇒ Boolean
97 98 99 |
# File 'lib/vanity/playground.rb', line 97 def failover_on_datastore_error? Vanity.configuration.failover_on_datastore_error end |
#load! ⇒ Object
149 150 151 |
# File 'lib/vanity/playground.rb', line 149 def load! Vanity.load! end |
#load_path ⇒ Object
31 32 33 |
# File 'lib/vanity/playground.rb', line 31 def load_path Vanity.configuration.experiments_path end |
#load_path=(path) ⇒ Object
37 38 39 |
# File 'lib/vanity/playground.rb', line 37 def load_path=(path) Vanity.configuration.experiments_path = path end |
#logger ⇒ Object
43 44 45 |
# File 'lib/vanity/playground.rb', line 43 def logger Vanity.configuration.logger end |
#logger=(logger) ⇒ Object
49 50 51 |
# File 'lib/vanity/playground.rb', line 49 def logger=(logger) Vanity.configuration.logger = logger end |
#metric(id) ⇒ Object
Returns a metric (raises NameError if no metric with that identifier).
161 162 163 |
# File 'lib/vanity/playground.rb', line 161 def metric(id) metrics[id.to_sym] or raise NameError, "No metric #{id}" end |
#on_datastore_error ⇒ Object
104 105 106 |
# File 'lib/vanity/playground.rb', line 104 def on_datastore_error Vanity.configuration.on_datastore_error end |
#on_datastore_error=(closure) ⇒ Object
110 111 112 |
# File 'lib/vanity/playground.rb', line 110 def on_datastore_error=(closure) Vanity.configuration.on_datastore_error = closure end |
#participant_info(participant_id) ⇒ Object
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)
191 192 193 194 195 196 197 198 |
# File 'lib/vanity/playground.rb', line 191 def participant_info(participant_id) participant_array = [] experiments.values.sort_by(&:name).each do |e| index = connection.ab_assigned(e.id, participant_id) participant_array << [e, e.alternatives[index.to_i]] if index end participant_array end |
#reconnect! ⇒ Object
Closes the current connection and establishes a new one.
233 234 235 |
# File 'lib/vanity/playground.rb', line 233 def reconnect! Vanity.reconnect! end |
#reload! ⇒ Object
143 144 145 |
# File 'lib/vanity/playground.rb', line 143 def reload! Vanity.reload! end |
#request_filter ⇒ Object
117 118 119 |
# File 'lib/vanity/playground.rb', line 117 def request_filter Vanity.configuration.request_filter end |
#request_filter=(filter) ⇒ Object
123 124 125 |
# File 'lib/vanity/playground.rb', line 123 def request_filter=(filter) Vanity.configuration.request_filter = filter end |
#track!(id, count = 1) ⇒ Object
Tracks an action associated with a metric.
171 172 173 |
# File 'lib/vanity/playground.rb', line 171 def track!(id, count = 1) metric(id).track!(count) end |
#use_js! ⇒ Object
65 66 67 |
# File 'lib/vanity/playground.rb', line 65 def use_js! Vanity.configuration.use_js = true end |
#using_js? ⇒ Boolean
71 72 73 |
# File 'lib/vanity/playground.rb', line 71 def using_js? Vanity.configuration.use_js end |