Class: SplitIoClient::LocalhostSplitManager

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

Instance Method Summary collapse

Methods included from LocalhostUtils

#load_localhost_mode_features, #store_features

Constructor Details

#initialize(splits_file, reload_rate = nil) ⇒ LocalhostSplitIoManager

Creates a new split manager instance that holds the splits from a given file

Parameters:

  • splits_file (File)

    the .split file that contains the splits

  • reload_rate (Integer) (defaults to: nil)

    the number of seconds to reload splits_file



12
13
14
15
16
17
# File 'lib/splitclient-rb/managers/localhost_split_manager.rb', line 12

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

  load_localhost_mode_features(splits_file, reload_rate)
end

Instance Method Details

#split(split_name) ⇒ Object

method to get a split view



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/splitclient-rb/managers/localhost_split_manager.rb', line 23

def split(split_name)
  features = @localhost_mode_features.find_all { |feat| feat[:feature] == split_name }

  return nil if features.nil?

  treatments = features.map { |feat| feat[:treatment] }

  configs = Hash[ features.map { |feat| [ feat[:treatment].to_sym, feat[:config] ] } ]

  {
    change_number: nil,
    killed:       false,
    name:         split_name,
    traffic_type:  nil,
    treatments:   treatments,
    configs: configs
  }
end

#split_namesObject

method to get the list of just split names. Ideal for ietrating and calling client.get_treatment



56
57
58
# File 'lib/splitclient-rb/managers/localhost_split_manager.rb', line 56

def split_names
  @localhost_mode_features.map{ |feat| feat[:feature]}.uniq
end

#splitsObject

method to get the split list from the client



46
47
48
49
50
# File 'lib/splitclient-rb/managers/localhost_split_manager.rb', line 46

def splits
  split_names.map do |split_name|
    split(split_name)
  end
end