module Vanity
All the cool stuff happens in other places. @see Vanity::Helper @see Vanity::Rails
@see Vanity::Playground
@see Vanity::Metric
@see Vanity::Experiment
@see Vanity::Configuration
@see Vanity::Connection
Run time configuration and helpers
Constants
- VERSION
Attributes
@since 2.0.0
@since 2.0.0
@since 2.0.0
Public Class Methods
Returns the current configuration.
@see Vanity::Configuration
@since 2.0.0
# File lib/vanity/vanity.rb, line 11 def self.configuration(set_if_needed=true) if defined?(@configuration) && @configuration @configuration elsif set_if_needed configure! end end
This is the preferred way to configure Vanity
.
@example
Vanity.configure do |config| config.use_js = true end
@since 2.0.0
# File lib/vanity/vanity.rb, line 37 def self.configure yield(configuration) end
@since 2.0.0
# File lib/vanity/vanity.rb, line 20 def self.configure! @configuration = Configuration.new end
This is the preferred way to programmatically create a new connection (or switch to a new connection). If no connection was established, the playground will create a new one by calling this method with no arguments.
@since 2.0.0 @see Vanity::Connection
# File lib/vanity/vanity.rb, line 94 def self.connect!(spec_or_nil=nil) spec_or_nil ||= configuration.connection_params # Legacy special config variables permitted in connection spec update_configuration_from_connection_params(spec_or_nil) # Legacy redis.yml fallback if spec_or_nil.nil? redis_url = configuration.redis_url_from_file if redis_url spec_or_nil = redis_url end end # Legacy connection url fallback if configuration.connection_url spec_or_nil = configuration.connection_url end @connection = Connection.new(spec_or_nil) end
Returns the current connection. Establishes new connection is necessary.
@since 2.0.0
# File lib/vanity/vanity.rb, line 80 def self.connection(connect_if_needed=true) if defined?(@connection) && @connection @connection elsif connect_if_needed connect! end end
Sets the Vanity
context. For example, when using Rails
this would be set by the set_vanity_context before filter (via Vanity::Rails#use_vanity).
# File lib/vanity/vanity.rb, line 54 def self.context=(context) Thread.current[:vanity_context] = context if context context.class.send(:define_method, :vanity_add_to_active_experiments) do |name, alternative| @_vanity_experiments ||= {} @_vanity_experiments[name] ||= alternative @_vanity_experiments[name].value end context.class.send(:alias_method, :vanity_store_experiment_for_js, :vanity_add_to_active_experiments) context.class.send(:define_method, :vanity_active_experiments) do @_vanity_experiments ||= {} end end context end
Destroys a connection
@since 2.0.0
# File lib/vanity/vanity.rb, line 119 def self.disconnect! if @connection @connection.disconnect! @connection = nil end end
@since 2.0.0
# File lib/vanity/vanity.rb, line 42 def self.logger configuration.logger end
The playground instance.
@see Vanity::Playground
# File lib/vanity/vanity.rb, line 138 def self.playground(load_if_needed=true) if @playground @playground elsif load_if_needed load! end end
# File lib/vanity/vanity.rb, line 126 def self.reconnect! disconnect! connect! end
Reloads all metrics and experiments. Rails
calls this for each request in development mode.
@since 2.0.0
# File lib/vanity/vanity.rb, line 164 def self.reload! unload! load! end
@since 2.0.0
# File lib/vanity/vanity.rb, line 25 def self.reset! @configuration = nil configuration end
# File lib/vanity/templates.rb, line 36 def template(name) @templates ||= Templates.new @templates.path(name) end
@since 2.0.0
# File lib/vanity/vanity.rb, line 156 def self.unload! @playground = nil end