class Rack::Logs::Viewer

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/rack/logs/viewer.rb, line 5
def initialize config
  @config = config
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/logs/viewer.rb, line 10
def call env
  contents = joined_logs(env.fetch('PATH_INFO','/'))
  if contents.empty?
    [404, headers, ['No Such File']]
  else
    [200, headers, contents]
  end
end

Private Instance Methods

files(path) click to toggle source
# File lib/rack/logs/viewer.rb, line 85
def files path
  Dir[@config.log_dir+'/'+@config.pattern].select do |filename|
    filename =~ Regexp.new( @config.log_dir + path )
  end
end
headers() click to toggle source
# File lib/rack/logs/viewer.rb, line 21
def headers
  {
    'Content-Type' => 'text/plain'
  }
end
joined_logs(path) click to toggle source
# File lib/rack/logs/viewer.rb, line 74
def joined_logs path
  JoinedFiles.new files(path), @config.lines
end
logs() click to toggle source
# File lib/rack/logs/viewer.rb, line 78
def logs
  files.inject({}) do |hash, filename|
    hash[filename] = ::File.read(filename)
    hash
  end
end