Module: SplitIoClient::LocalhostUtils

Included in:
LocalhostSplitClient, LocalhostSplitManager
Defined in:
lib/splitclient-rb/localhost_utils.rb

Instance Method Summary collapse

Instance Method Details

#load_localhost_mode_features(splits_file, reload_rate = nil) ⇒ Object

method to set localhost mode features by reading the given .splits

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

Returns:

  • nil



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/splitclient-rb/localhost_utils.rb', line 9

def load_localhost_mode_features(splits_file, reload_rate = nil)
  return @localhost_mode_features unless File.exists?(splits_file)

  store_features(splits_file)

  return unless reload_rate

  Thread.new do
    loop do
      @localhost_mode_features = []
      store_features(splits_file)

      sleep(::Utilities.randomize_interval(reload_rate))
    end
  end
end

#store_features(splits_file) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/splitclient-rb/localhost_utils.rb', line 26

def store_features(splits_file)
  File.open(splits_file).each do |line|
    feature, treatment = line.strip.split(' ')

    next if line.start_with?('#') || line.strip.empty?

    @localhost_mode_features << { feature: feature, treatment: treatment }
  end
end