Module: Clarity::GrepRenderer

Defined in:
lib/clarity/grep_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rendererObject



6
7
8
# File 'lib/clarity/grep_renderer.rb', line 6

def renderer
  @renderer ||= LogRenderer.new
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/clarity/grep_renderer.rb', line 3

def response
  @response
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/clarity/grep_renderer.rb', line 25

def close
  ProcessTree.kill(get_status.pid)      
end

#flushObject



21
22
23
# File 'lib/clarity/grep_renderer.rb', line 21

def flush
  response.send_chunks
end

#receive_data(data) ⇒ Object

once download is complete, send it to client



11
12
13
14
15
16
17
18
19
# File 'lib/clarity/grep_renderer.rb', line 11

def receive_data(data)
  @buffer ||= StringScanner.new("")
  @buffer << data

  while line = @buffer.scan_until(/\n/)
    response.chunk renderer.render(line)
    flush
  end      
end

#unbindObject



29
30
31
32
33
34
35
# File 'lib/clarity/grep_renderer.rb', line 29

def unbind          
  response.chunk renderer.finalize
  response.chunk ''
  close
  flush
  puts 'Done'
end