Class: SplitIoClient::LocalhostSplitClient

Inherits:
Object
  • Object
show all
Includes:
LocalhostUtils
Defined in:
lib/splitclient-rb/clients/localhost_split_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LocalhostUtils

#load_localhost_mode_features, #store_features

Constructor Details

#initialize(splits_file, reload_rate = nil) ⇒ LocalhostSplitIoClient

Creates a new split client instance that reads from the given splits file

Parameters:

  • splits_file (File)

    file that contains some splits



16
17
18
19
20
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 16

def initialize(splits_file, reload_rate = nil)
  @localhost_mode = true
  @localhost_mode_features = []
  load_localhost_mode_features(splits_file, reload_rate)
end

Instance Attribute Details

#localhost_modeObject (readonly)

variables to if the sdk is being used in localhost mode and store the list of features



7
8
9
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 7

def localhost_mode
  @localhost_mode
end

#localhost_mode_featuresObject (readonly)

Returns the value of attribute localhost_mode_features.



8
9
10
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 8

def localhost_mode_features
  @localhost_mode_features
end

Class Method Details

.sdk_versionstring

method that returns the sdk gem version

Returns:

  • (string)

    version value for this sdk



26
27
28
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 26

def self.sdk_version
  'ruby-'+SplitIoClient::VERSION
end

Instance Method Details

#get_treatment(id, feature, attributes = nil) ⇒ Treatment

obtains the treatment for a given feature

Parameters:

  • id (string)

    user id

  • feature (string)

    name of the feature that is being validated

Returns:

  • (Treatment)

    treatment constant value



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 43

def get_treatment(id, feature, attributes = nil)
  unless id
    SplitIoClient.configuration.logger.warn('id was null for feature: ' + feature)
    return SplitIoClient::Engine::Models::Treatment::CONTROL
  end

  unless feature
    SplitIoClient.configuration.logger.warn('feature was null for id: ' + id)
    return SplitIoClient::Engine::Models::Treatment::CONTROL
  end

  result = get_localhost_treatment(feature)
end

#get_treatments(key, split_names, attributes = nil) ⇒ Object



30
31
32
33
34
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 30

def get_treatments(key, split_names, attributes = nil)
  split_names.each_with_object({}) do |name, memo|
    memo.merge!(name => get_treatment(key, name, attributes))
  end
end

#trackObject



57
58
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 57

def track
end