Sha256: b61be255d7b3061d688b64804e913ef5c7f7c934eff93085a1009f1346fbd8cf
Contents?: true
Size: 1.19 KB
Versions: 14
Compression:
Stored size: 1.19 KB
Contents
module Unleash class Metrics attr_accessor :features, :features_lock def initialize self.features = {} self.features_lock = Mutex.new end def to_s self.features_lock.synchronize do return self.features.to_json end end def increment(feature, choice) raise "InvalidArgument choice must be :yes or :no" unless [:yes, :no].include? choice self.features_lock.synchronize do self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature self.features[feature][choice] += 1 end end def increment_variant(feature, choice, variant) self.features_lock.synchronize do self.features[feature] = { yes: 0, no: 0 } unless self.features.include? feature self.features[feature][choice] += 1 self.features[feature]['variants'] = {} unless self.features[feature].include? 'variants' self.features[feature]['variants'][variant] = 0 unless self.features[feature]['variants'].include? variant self.features[feature]['variants'][variant] += 1 end end def reset self.features_lock.synchronize do self.features = {} end end end end
Version data entries
14 entries across 14 versions & 1 rubygems