Class: Unleash::Metrics
- Inherits:
-
Object
- Object
- Unleash::Metrics
- Defined in:
- lib/unleash/metrics.rb
Instance Attribute Summary collapse
-
#features ⇒ Object
Returns the value of attribute features.
Instance Method Summary collapse
- #increment(feature, choice) ⇒ Object
- #increment_variant(feature, variant) ⇒ Object
-
#initialize ⇒ Metrics
constructor
NOTE: no mutexes for features.
- #reset ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Metrics
NOTE: no mutexes for features
8 9 10 |
# File 'lib/unleash/metrics.rb', line 8 def initialize self.features = {} end |
Instance Attribute Details
#features ⇒ Object
Returns the value of attribute features.
4 5 6 |
# File 'lib/unleash/metrics.rb', line 4 def features @features end |
Instance Method Details
#increment(feature, choice) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/unleash/metrics.rb', line 16 def increment(feature, choice) raise "InvalidArgument choice must be :yes or :no" unless [:yes, :no].include? choice self.features[feature] = {yes: 0, no: 0} unless self.features.include? feature self.features[feature][choice] += 1 end |
#increment_variant(feature, variant) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/unleash/metrics.rb', line 23 def increment_variant(feature, variant) self.features[feature] = {yes: 0, no: 0} unless self.features.include? feature self.features[feature]['variant'] = {} unless self.features[feature].include? 'variant' self.features[feature]['variant'][variant] = 0 unless self.features[feature]['variant'].include? variant self.features[feature]['variant'][variant] += 1 end |
#reset ⇒ Object
30 31 32 |
# File 'lib/unleash/metrics.rb', line 30 def reset self.features = {} end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/unleash/metrics.rb', line 12 def to_s self.features.to_json end |