Module: AmplitudeExperiment

Defined in:
lib/experiment/factory.rb,
lib/experiment/user.rb,
lib/experiment/cookie.rb,
lib/experiment/variant.rb,
lib/experiment/version.rb,
lib/amplitude-experiment.rb,
lib/experiment/util/hash.rb,
lib/experiment/local/client.rb,
lib/experiment/local/config.rb,
lib/experiment/local/fetcher.rb,
lib/experiment/remote/client.rb,
lib/experiment/remote/config.rb,
lib/experiment/util/lru_cache.rb,
lib/experiment/persistent_http_client.rb,
lib/experiment/local/assignment/assignment.rb,
lib/experiment/local/assignment/assignment_config.rb,
lib/experiment/local/assignment/assignment_filter.rb,
lib/experiment/local/assignment/assignment_service.rb

Overview

AmplitudeExperiment

Defined Under Namespace

Classes: AmplitudeCookie, Assignment, AssignmentConfig, AssignmentFilter, AssignmentService, CacheItem, LRUCache, ListNode, LocalEvaluationClient, LocalEvaluationConfig, LocalEvaluationFetcher, PersistentHttpClient, RemoteEvaluationClient, RemoteEvaluationConfig, User, Variant

Constant Summary collapse

VERSION =
'1.2.4'.freeze
FLAG_TYPE_MUTUAL_EXCLUSION_GROUP =
'mutual_exclusion_group'.freeze
FLAG_TYPE_HOLDOUT_GROUP =
'holdout-group'.freeze
DAY_MILLIS =
86_400_000

Class Method Summary collapse

Class Method Details

.hash_code(string) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/experiment/util/hash.rb', line 3

def self.hash_code(string)
  hash = 0
  return hash if string.empty?

  string.each_char do |char|
    chr_code = char.ord
    hash = ((hash << 5) - hash) + chr_code
    hash &= 0xFFFFFFFF
  end

  hash
end

.initialize_local(api_key, config = nil) ⇒ Object

Initializes a local evaluation Client. A local evaluation client can evaluate local flags or experiments for a user without requiring a remote call to the amplitude evaluation server. In order to best leverage local evaluation, all flags, and experiments being evaluated server side should be configured as local.

Parameters:

  • api_key (String)

    The environment API Key

  • config (Config) (defaults to: nil)

    Optional Config.



22
23
24
25
# File 'lib/experiment/factory.rb', line 22

def self.initialize_local(api_key, config = nil)
  @local_instance.store(api_key, LocalEvaluationClient.new(api_key, config)) unless @local_instance.key?(api_key)
  @local_instance.fetch(api_key)
end

.initialize_remote(api_key, config = nil) ⇒ Object

Initializes a singleton Client. This method returns a default singleton instance, subsequent calls to

init will return the initial instance regardless of input.

Parameters:

  • api_key (String)

    The environment API Key

  • config (Config) (defaults to: nil)

    Optional Config.



11
12
13
14
# File 'lib/experiment/factory.rb', line 11

def self.initialize_remote(api_key, config = nil)
  @remote_instance.store(api_key, RemoteEvaluationClient.new(api_key, config)) unless @remote_instance.key?(api_key)
  @remote_instance.fetch(api_key)
end