Class: Dial::PanelInjector
- Inherits:
-
Object
- Object
- Dial::PanelInjector
- Defined in:
- lib/dial/middleware.rb
Instance Method Summary collapse
- #call(stream) ⇒ Object
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(original_body, panel_html) ⇒ PanelInjector
constructor
A new instance of PanelInjector.
Constructor Details
#initialize(original_body, panel_html) ⇒ PanelInjector
Returns a new instance of PanelInjector.
139 140 141 142 143 |
# File 'lib/dial/middleware.rb', line 139 def initialize original_body, panel_html @original_body = original_body @panel_html = panel_html @injected = false end |
Instance Method Details
#call(stream) ⇒ Object
164 165 166 167 168 |
# File 'lib/dial/middleware.rb', line 164 def call stream each { |chunk| stream.write chunk } ensure close end |
#close ⇒ Object
160 161 162 |
# File 'lib/dial/middleware.rb', line 160 def close @original_body.close if @original_body.respond_to? :close end |
#each ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/dial/middleware.rb', line 145 def each @original_body.each do |chunk| if !@injected && chunk.include?("</body>") @injected = true yield chunk.sub("</body>", "#{@panel_html}\n</body>") else yield chunk end end yield @panel_html unless @injected ensure close end |