Sha256: 86214d5ecf224754515d99c55206e8715c7024824e51f604635bad14e56ad535
Contents?: true
Size: 1.85 KB
Versions: 23
Compression:
Stored size: 1.85 KB
Contents
module SplitIoClient # # class to manage cached impressions # class Impressions < NoMethodError # the queue of cached impression values # # @return [object] array of impressions attr_accessor :queue # max number of cached entries for impressions # # @return [int] max numbre of entries attr_accessor :max_number_of_keys # # initializes the class # # @param max [int] max number of cached entries def initialize(max) @queue = Queue.new @max_number_of_keys = max end # # generates a new entry for impressions list # # @param id [string] user key # @param feature [string] feature name # @param treatment [string] treatment value # @param time [time] time value in milisenconds # # @return void def log(id, feature, treatment, time) impressions = KeyImpressions.new(id, treatment, time) @queue << {feature: feature, impressions: impressions} end # # clears the impressions queue # # @returns void def clear popped_impressions = [] begin loop do impression_element = @queue.pop(true) feature_hash = popped_impressions.find { |i| i[:feature] == impression_element[:feature] } if feature_hash.nil? popped_impressions << {feature: impression_element[:feature], impressions: [] << impression_element[:impressions]} else feature_hash[:impressions] << impression_element[:impressions] end end rescue ThreadError end popped_impressions end end # # small class to use as DTO for impressions # class KeyImpressions attr_accessor :key attr_accessor :treatment attr_accessor :time def initialize(key, treatment, time) @key = key @treatment = treatment @time = time end end end
Version data entries
23 entries across 23 versions & 1 rubygems