Class: Determinator::Tracking::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/tracking/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Tracker

Returns a new instance of Tracker.



9
10
11
12
13
14
# File 'lib/determinator/tracking/tracker.rb', line 9

def initialize(type)
  @determinations = Hash.new(0)
  @type = type
  @monotonic_start = now
  @start = Time.now
end

Instance Attribute Details

#determinationsObject (readonly)

Returns the value of attribute determinations.



7
8
9
# File 'lib/determinator/tracking/tracker.rb', line 7

def determinations
  @determinations
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/determinator/tracking/tracker.rb', line 7

def type
  @type
end

Instance Method Details

#finish!(endpoint:, error:, **attributes) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/determinator/tracking/tracker.rb', line 27

def finish!(endpoint:, error:, **attributes)
  request_time = now - @monotonic_start
  Determinator::Tracking::Request.new(
    start: @start,
    type: type,
    time: request_time,
    endpoint: endpoint,
    error: error,
    attributes: attributes,
    determinations: determinations,
    context: Determinator::Tracking.context
  )
end

#track(id, guid, feature, determination) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/determinator/tracking/tracker.rb', line 16

def track(id, guid, feature, determination)
  determinations[
    Determinator::Tracking::Determination.new(
      id: id,
      guid: guid,
      feature_id: feature.identifier,
      determination: determination
    )
  ] += 1
end