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_mode ⇒ Object (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_features ⇒ Object (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_version ⇒ string

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(key, split_name, attributes = nil) ⇒ string

obtains the treatment for a given feature

Parameters:

  • key (string) —

    evaluation key, only used with yaml split files

  • split_name (string) —

    name of the feature that is being validated

  • attributes (hash) (defaults to: nil) —

    kept for consistency with actual SDK client. Omitted in calls

Returns:

  • (string) —

    corresponding treatment



66
67
68
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 66

def get_treatment(key, split_name, attributes = nil)
  get_localhost_treatment(key, split_name, attributes)[:treatment]
end

#get_treatment_with_config(key, split_name, attributes = nil) ⇒ hash

obtains the treatment and config for a given feature

Parameters:

  • key (string) —

    evaluation key, only used with yaml split files

  • split_name (string) —

    name of the feature that is being validated

  • attributes (hash) (defaults to: nil) —

    kept for consistency with actual SDK client. Omitted in calls

Returns:

  • (hash) —

    corresponding treatment and config



78
79
80
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 78

def get_treatment_with_config(key, split_name, attributes = nil)
  get_localhost_treatment(key, split_name, attributes, 'get_treatment_with_config')
end

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

obtains the treatments for a given set of features

Parameters:

  • key (string) —

    evaluation key, only used with yaml split files

  • split_names (array) —

    name of the features being validated

  • attributes (hash) (defaults to: nil) —

    kept for consistency with actual SDK client. Omitted in calls

Returns:

  • (hash) —

    map of treatments (split_name, treatment_name)



50
51
52
53
54
55
56
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 50

def get_treatments(key, split_names, attributes = nil)
  treatments = get_localhost_treatments(key, split_names, attributes)
  return treatments if treatments.nil?
  keys = treatments.keys
  treats = treatments.map { |_,t| t[:treatment]  }
  Hash[keys.zip(treats)]
end

#get_treatments_with_config(key, split_names, attributes = nil) ⇒ hash

obtains the treatments and configs for a given set of features

Parameters:

  • key (string) —

    evaluation key, only used with yaml split files

  • split_names (array) —

    name of the features being validated

  • attributes (hash) (defaults to: nil) —

    kept for consistency with actual SDK client. Omitted in calls

Returns:

  • (hash) —

    map of treatments (split_name, treatment)



38
39
40
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 38

def get_treatments_with_config(key, split_names, attributes = nil)
  get_localhost_treatments(key, split_names, attributes, 'get_treatments_with_config')
end

#track ⇒ Object



82
83
# File 'lib/splitclient-rb/clients/localhost_split_client.rb', line 82

def track
end