4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/svelte_on_rails/lib/metrics.rb', line 4
def self.fragment
m = SvelteOnRails::Configuration.instance.request_metrics || {}
cnf = SvelteOnRails::Configuration.instance
if !cnf.build_status['passed']
'SVELTE BUILD FAILED!'
elsif m[:render_failed]
'SVELTE RENDER FAILED!'
elsif m[:ssr_server_unreachable]
'SVELTE SSR SERVER UNREACHABLE!'
else
w = (cnf.watch_changes? ? cnf.build_status['warnings_count'] : nil)
bld = [
if m[:build]
m[:build] == 1 ? 'build' : "#{m[:build]} builds"
else
nil
end,
(w && w >= 1 ? "#{w} warnings" : nil)
].compact
acts = [:from_cache, :empty, :rendered].map do |k|
act = {
from_cache: 'cached',
empty: 'empty',
rendered: 'rendered',
}[k]
"#{m[k]} #{act}" if m[k] && m[k] > 0
end.compact
if acts.present? || bld.present?
str = [
(bld.join(', ') if bld.present?),
(acts.present? ? acts.join(', ') : nil),
"#{m[:total_time].round(1)}ms"
].compact.join(', ')
"Svelte: #{str}"
end
end
end
|