Class: WebConsole::Injector

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/injector.rb

Overview

Injects content into a Rack body.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Injector

Returns a new instance of Injector.



6
7
8
9
10
11
# File 'lib/web_console/injector.rb', line 6

def initialize(body)
  @body = "".dup

  body.each { |part| @body << part }
  body.close if body.respond_to?(:close)
end

Instance Method Details

#inject(content) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/web_console/injector.rb', line 13

def inject(content)
  if position = @body.rindex("</body>")
    [ @body.insert(position, content) ]
  else
    [ @body << content ]
  end
end