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.



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

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



21
22
23
# File 'lib/scout_apm/instant/middleware.rb', line 21

def add_to_body(content)
  @to_add_to_body << content
end

#add_to_head(content) ⇒ Object



17
18
19
# File 'lib/scout_apm/instant/middleware.rb', line 17

def add_to_head(content)
  @to_add_to_head << content
end

#resObject



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

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