Sha256: 9d6b67d4ba1c3d8b1c54d4100f1e0e03be25cad96322ffd7a2d78a5b0aa981a3

Contents?: true

Size: 1 KB

Versions: 79

Compression:

Stored size: 1 KB

Contents

module SplitIoClient
  module LocalhostUtils
    #
    # method to set localhost mode features by reading the given .splits
    #
    # @param splits_file [File] the .split file that contains the splits
    # @param reload_rate [Integer] the number of seconds to reload splits_file
    # @return nil
    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(SplitIoClient::Utilities.randomize_interval(reload_rate))
        end
      end
    end

    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
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
splitclient-rb-5.1.3.pre.rc4-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc4 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc3-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc3 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc2-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc2 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.4.pre.rc1-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.4.pre.rc1 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc1-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.3.pre.rc1 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2.pre.rc1-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2.pre.rc1 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2.pre.rc21 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.2.pre.rc21-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.1-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.1 lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.1.pre.rc2-java lib/splitclient-rb/localhost_utils.rb
splitclient-rb-5.1.1.pre.rc2 lib/splitclient-rb/localhost_utils.rb