Class: Quilt::Performance::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/quilt_rails/performance/event.rb

Constant Summary collapse

TYPE =
{
  time_to_first_byte: 'ttfb',
  time_to_first_paint: 'ttfp',
  time_to_first_contentful_paint: 'ttfcp',
  dom_content_loaded: 'dcl',
  first_input_delay: 'fid',
  load: 'load',
  long_task: 'longtask',
  usable: 'usable',
  graphql: 'graphql',
  script_download: 'script',
  style_download: 'style',
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, start:, duration:, metadata:) ⇒ Event

Returns a new instance of Event.



43
44
45
46
47
48
# File 'lib/quilt_rails/performance/event.rb', line 43

def initialize(type:, start:, duration:, metadata:)
  @type = type
  @start = start
  @duration = duration
  @metadata = 
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



24
25
26
# File 'lib/quilt_rails/performance/event.rb', line 24

def connection
  @connection
end

#durationObject

Returns the value of attribute duration.



22
23
24
# File 'lib/quilt_rails/performance/event.rb', line 22

def duration
  @duration
end

#metadataObject

Returns the value of attribute metadata.



23
24
25
# File 'lib/quilt_rails/performance/event.rb', line 23

def 
  @metadata
end

#startObject

Returns the value of attribute start.



21
22
23
# File 'lib/quilt_rails/performance/event.rb', line 21

def start
  @start
end

#typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/quilt_rails/performance/event.rb', line 20

def type
  @type
end

Class Method Details

.from_params(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/quilt_rails/performance/event.rb', line 26

def self.from_params(params)
  params.require([:type, :start, :duration])

  attributes = {
    type: params[:type],
    start: params[:start],
    duration: params[:duration],
    metadata: nil,
  }

  if params[:metadata]
    attributes[:metadata] = EventMetadata.from_params(params[:metadata])
  end

  Event.new(**attributes)
end

Instance Method Details

#has_metadata?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/quilt_rails/performance/event.rb', line 69

def has_metadata?
  !.nil?
end

#metric_nameObject



60
61
62
63
64
65
66
67
# File 'lib/quilt_rails/performance/event.rb', line 60

def metric_name
  type_name = TYPE.key(type)
  if LIFECYCLE[type_name].nil?
    type
  else
    LIFECYCLE[type_name]
  end
end

#valueObject



50
51
52
53
54
55
56
57
58
# File 'lib/quilt_rails/performance/event.rb', line 50

def value
  raw_value = if type == TYPE[:first_input_delay]
    duration
  else
    start
  end

  raw_value.round
end