Module: Split

Extended by:
Split
Included in:
Split
Defined in:
lib/split/alternative.rb,
lib/split.rb,
lib/split/trial.rb,
lib/split/engine.rb,
lib/split/helper.rb,
lib/split/metric.rb,
lib/split/zscore.rb,
lib/split/version.rb,
lib/split/dashboard.rb,
lib/split/exceptions.rb,
lib/split/experiment.rb,
lib/split/persistence.rb,
lib/split/configuration.rb,
lib/split/dashboard/helpers.rb,
lib/split/experiment_catalog.rb,
lib/split/algorithms/whiplash.rb,
lib/split/encapsulated_helper.rb,
lib/split/persistence/redis_adapter.rb,
lib/split/algorithms/weighted_sample.rb,
lib/split/persistence/cookie_adapter.rb,
lib/split/persistence/session_adapter.rb

Overview

Split’s helper exposes all kinds of methods we don’t want to mix into our model classes.

This module exposes only two methods

- ab_test and 
- ab_test_finished

that can safely be mixed into any class.

Passes the instance of the class that it’s mixed into to the Split persistence adapter as context.

Defined Under Namespace

Modules: Algorithms, DashboardHelpers, EncapsulatedHelper, Helper, Persistence, Zscore Classes: Alternative, Configuration, Dashboard, Engine, Experiment, ExperimentCatalog, ExperimentNotFound, InvalidExperimentsFormatError, InvalidPersistenceAdapterError, Metric, Trial

Constant Summary collapse

MAJOR =
1
MINOR =
0
PATCH =
0
VERSION =
[MAJOR, MINOR, PATCH].join('.')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



23
24
25
# File 'lib/split.rb', line 23

def configuration
  @configuration
end

Instance Method Details

#configure {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Split.configure do |config|
  config.ignore_ip_addresses = '192.168.2.1'
end

Yields:



66
67
68
69
# File 'lib/split.rb', line 66

def configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

#redisObject

Returns the current Redis connection. If none has been created, will create a new one.



54
55
56
57
58
# File 'lib/split.rb', line 54

def redis
  return @redis if @redis
  self.redis = 'localhost:6379'
  self.redis
end

#redis=(server) ⇒ Object

Accepts:

1. A 'hostname:port' string
2. A 'hostname:port:db' string (to select the Redis db)
3. A 'hostname:port/namespace' string (to set the Redis namespace)
4. A redis URL string 'redis://host:port'
5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
   or `Redis::Namespace`.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/split.rb', line 32

def redis=(server)
  if server.respond_to? :split
    if server["redis://"]
      redis = Redis.connect(:url => server, :thread_safe => true)
    else
      server, namespace = server.split('/', 2)
      host, port, db = server.split(':')
      redis = Redis.new(:host => host, :port => port,
        :thread_safe => true, :db => db)
    end
    namespace ||= :split

    @redis = Redis::Namespace.new(namespace, :redis => redis)
  elsif server.respond_to? :namespace=
    @redis = server
  else
    @redis = Redis::Namespace.new(:split, :redis => server)
  end
end