Class: Vanity::Playground

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializePlayground

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

#experimentsObject (readonly)

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

See Also:



19
20
21
# File 'lib/vanity/playground.rb', line 19

def experiments
  @experiments
end

#metricsObject (readonly)

Deprecated.

Returns hash of metrics (key is metric id).

See Also:

Since:

  • 1.1.0



13
14
15
# File 'lib/vanity/playground.rb', line 13

def metrics
  @metrics
end

Instance Method Details

#add_participant_pathObject

Deprecated.

See Also:

  • Configuration#add_participant_route


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

Deprecated.


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

Deprecated.

See Also:

  • Configuration#collecting

Since:

  • 1.4.0



137
138
139
# File 'lib/vanity/playground.rb', line 137

def collecting=(enabled)
  Vanity.configuration.collecting = enabled
end

#collecting?Boolean

Deprecated.

Returns:

  • (Boolean)

See Also:

  • Configuration#collecting

Since:

  • 1.4.0



130
131
132
# File 'lib/vanity/playground.rb', line 130

def collecting?
  Vanity.configuration.collecting
end

#connected?Boolean

Deprecated.

Returns:

  • (Boolean)

See Also:

Since:

  • 1.4.0



218
219
220
# File 'lib/vanity/playground.rb', line 218

def connected?
  Vanity.connection.connected?
end

#connectionObject

Deprecated.

See Also:

Since:

  • 1.4.0



211
212
213
# File 'lib/vanity/playground.rb', line 211

def connection
  Vanity.connection.adapter
end

#custom_templates_pathObject

Deprecated.

See Also:

  • Configuration#templates_path


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

Deprecated.

See Also:

Since:

  • 1.4.0



225
226
227
# File 'lib/vanity/playground.rb', line 225

def disconnect!
  Vanity.disconnect!
end

#establish_connection(spec = nil) ⇒ Object

Deprecated.

See Also:

Since:

  • 1.4.0



203
204
205
206
# File 'lib/vanity/playground.rb', line 203

def establish_connection(spec = nil)
  disconnect!
  Vanity.connect!(spec)
end

#experiment(name) ⇒ Object

Deprecated.

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

See Also:



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

Returns:

  • (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

Deprecated.

See Also:

  • Configuration#failover_on_datastore_error

Since:

  • 1.9.0



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

Deprecated.

Returns:

  • (Boolean)

See Also:

  • Configuration#failover_on_datastore_error

Since:

  • 1.9.0



97
98
99
# File 'lib/vanity/playground.rb', line 97

def failover_on_datastore_error?
  Vanity.configuration.failover_on_datastore_error
end

#load!Object

Deprecated.

See Also:

  • Vanity#load!


149
150
151
# File 'lib/vanity/playground.rb', line 149

def load!
  Vanity.load!
end

#load_pathObject

Deprecated.

See Also:

  • Configuration#experiments_path


31
32
33
# File 'lib/vanity/playground.rb', line 31

def load_path
  Vanity.configuration.experiments_path
end

#load_path=(path) ⇒ Object

Deprecated.

See Also:

  • Configuration#experiments_path


37
38
39
# File 'lib/vanity/playground.rb', line 37

def load_path=(path)
  Vanity.configuration.experiments_path = path
end

#loggerObject

Deprecated.

See Also:

  • Configuration#logger


43
44
45
# File 'lib/vanity/playground.rb', line 43

def logger
  Vanity.configuration.logger
end

#logger=(logger) ⇒ Object

Deprecated.

See Also:

  • Configuration#logger


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).

See Also:

Since:

  • 1.1.0



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_errorObject

Deprecated.

See Also:

  • Configuration#on_datastore_error

Since:

  • 1.9.0



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

Deprecated.

See Also:

  • Configuration#on_datastore_error


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

Deprecated.

Closes the current connection and establishes a new one.

Since:

  • 1.3.0



233
234
235
# File 'lib/vanity/playground.rb', line 233

def reconnect!
  Vanity.reconnect!
end

#reload!Object

Deprecated.

See Also:

  • Vanity#reload!


143
144
145
# File 'lib/vanity/playground.rb', line 143

def reload!
  Vanity.reload!
end

#request_filterObject

Deprecated.

See Also:

  • Configuration#request_filter

Since:

  • 1.9.0



117
118
119
# File 'lib/vanity/playground.rb', line 117

def request_filter
  Vanity.configuration.request_filter
end

#request_filter=(filter) ⇒ Object

Deprecated.


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.

Examples:

Vanity.playground.track! :uploaded_video

Since:

  • 1.1.0



171
172
173
# File 'lib/vanity/playground.rb', line 171

def track!(id, count = 1)
  metric(id).track!(count)
end

#use_js!Object

Deprecated.

See Also:

  • Configuration#use_js


65
66
67
# File 'lib/vanity/playground.rb', line 65

def use_js!
  Vanity.configuration.use_js = true
end

#using_js?Boolean

Deprecated.

Returns:

  • (Boolean)

See Also:

  • Configuration#use_js


71
72
73
# File 'lib/vanity/playground.rb', line 71

def using_js?
  Vanity.configuration.use_js
end