Class: MetricsEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/ff/ruby/server/sdk/api/metrics_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_config, target, variation, logger) ⇒ MetricsEvent

Returns a new instance of MetricsEvent.



5
6
7
8
9
10
11
12
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 5

def initialize(feature_config, target, variation, logger)

  @target = target
  @variation = variation
  @feature_config = feature_config
  @logger = logger
  freeze
end

Instance Attribute Details

#feature_configObject

Returns the value of attribute feature_config.



3
4
5
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 3

def feature_config
  @feature_config
end

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 3

def target
  @target
end

#variationObject

Returns the value of attribute variation.



3
4
5
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 3

def variation
  @variation
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 14

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 18

def eql?(other)
  # Guard clause other is the same type.
  # While it should be, this adds protection for an edge case we are seeing with very large
  # project sizes. Issue being tracked in FFM-12192, and once resolved, can feasibly remove
  # these checks in a future release.
  unless other.is_a?(MetricsEvent)
    # We should always have a logger available except when we've deep cloned this class.  We don't do any
    # equality check on clones in metrics code anyway, so this is just a safety check.
    if @logger
      @logger.warn("Warning: Attempted to compare MetricsEvent with #{other.class.name}")
    end
    return false
  end

  feature_config.feature == other.feature_config.feature and
    variation.identifier == other.variation.identifier and
    target.identifier == other.target.identifier
end

#hashObject



37
38
39
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 37

def hash
  feature_config.feature.hash | variation.identifier.hash | target.identifier.hash
end

#marshal_dumpObject

Exclude logger from serialization



43
44
45
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 43

def marshal_dump
  [@feature_config, @target, @variation]
end

#marshal_load(array) ⇒ Object



47
48
49
50
# File 'lib/ff/ruby/server/sdk/api/metrics_event.rb', line 47

def marshal_load(array)
  @feature_config, @target, @variation = array
  @logger = nil
end