Class: ScoutApm::Instant::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instant/middleware.rb

Overview

an abstraction for manipulating the HTML we capture in the middleware

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Page

Returns a new instance of Page.



8
9
10
11
12
13
14
15
16
17
# File 'lib/scout_apm/instant/middleware.rb', line 8

def initialize(html)
  @html = html

  if html.is_a?(Array)
    @html = html.inject("") { |memo, str| memo + str }
  end

  @to_add_to_head = []
  @to_add_to_body = []
end

Instance Method Details

#add_to_body(content) ⇒ Object



23
24
25
# File 'lib/scout_apm/instant/middleware.rb', line 23

def add_to_body(content)
  @to_add_to_body << content
end

#add_to_head(content) ⇒ Object



19
20
21
# File 'lib/scout_apm/instant/middleware.rb', line 19

def add_to_head(content)
  @to_add_to_head << content
end

#resObject



27
28
29
30
31
32
33
# File 'lib/scout_apm/instant/middleware.rb', line 27

def res
  i = @html.index("</body>")
  @html = @html.insert(i, @to_add_to_body.join("")) if i
  i = @html.index("</head>")
  @html = @html.insert(i, @to_add_to_head.join("")) if i
  @html
end