Class: LogsViewer::Display
- Inherits:
-
Object
- Object
- LogsViewer::Display
- Defined in:
- lib/logs_viewer/display.rb
Instance Method Summary collapse
- #call(env = {}) ⇒ Object
-
#initialize(app) ⇒ Display
constructor
A new instance of Display.
- #view_generate(data) ⇒ Object
Constructor Details
#initialize(app) ⇒ Display
Returns a new instance of Display.
4 5 6 7 8 |
# File 'lib/logs_viewer/display.rb', line 4 def initialize(app) @app = app @number_lines = LogsViewer::Config.number_lines @log_dir = LogsViewer::Config.log_dir end |
Instance Method Details
#call(env = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/logs_viewer/display.rb', line 10 def call(env = {}) if env["PATH_INFO"]=~/^\/logs/ @data = { list: LogsViewer::Handler.list(@log_dir), lines: [] } params = Rack::Utils.parse_nested_query(env["QUERY_STRING"]) if params.has_key? 'file' log_file = params['file'] number_lines = (params.has_key? 'number_lines') ? params['number_lines'] : @number_lines @data[:lines] = `tail -n "#{number_lines}" "#{log_file}"` [200,{"Content-Type"=>"text/html"},[view_generate(@data)]] else [200,{"Content-Type"=>"text/html"},[view_generate(@data)]] end else @app.call(env) end end |
#view_generate(data) ⇒ Object
33 34 35 36 37 |
# File 'lib/logs_viewer/display.rb', line 33 def view_generate(data) temp = LogsViewer::Handler.file_open("../views/display.html.erb") temp = ERB.new(temp) return temp.result(binding) end |