lib/logster/middleware/viewer.rb in logster-1.4.0.pre vs lib/logster/middleware/viewer.rb in logster-2.0.0.pre

- old
+ new

@@ -11,11 +11,11 @@ def initialize(app) @app = app @logs_path = Logster.config.subdirectory @path_regex = Regexp.new("^(#{@logs_path}$)|^(#{@logs_path}(/.*))$") - @store = Logster.store or raise ArgumentError.new("store") + (@store = Logster.store) || raise(ArgumentError.new("store")) @assets_path = File.expand_path("../../../../assets", __FILE__) @fileserver = Rack::File.new(@assets_path) end @@ -44,11 +44,11 @@ unless message return [404, {}, ["Message not found"]] end Logster.store.delete(message) - return [301, {"Location" => "#{@logs_path}/"}, []] + return [301, { "Location" => "#{@logs_path}/" }, []] elsif resource =~ /\/(un)?protect\/([0-9a-f]+)$/ off = $1 == "un" key = $2 @@ -57,17 +57,17 @@ return [404, {}, ["Message not found"]] end if off if Logster.store.unprotect(key) - return [301, {"Location" => "#{@logs_path}/show/#{key}?protected=false"}, []] + return [301, { "Location" => "#{@logs_path}/show/#{key}?protected=false" }, []] else return [500, {}, ["Failed"]] end else if Logster.store.protect(key) - return [301, {"Location" => "#{@logs_path}/show/#{key}?protected=true"}, []] + return [301, { "Location" => "#{@logs_path}/show/#{key}?protected=true" }, []] else return [500, {}, ["Failed"]] end end @@ -79,11 +79,11 @@ return [404, {}, ["Message not found"]] end Logster.store.solve(key) - return [301, {"Location" => "#{@logs_path}"}, []] + return [301, { "Location" => "#{@logs_path}" }, []] elsif resource =~ /\/clear$/ if env[REQUEST_METHOD] != "POST" return [405, {}, ["GET not allowed for /clear"]] end @@ -98,18 +98,18 @@ unless message return [404, {}, ["Message not found"]] end if json - [200, {"Content-Type" => "application/json; charset=utf-8"}, [message.to_json]] + [200, { "Content-Type" => "application/json; charset=utf-8" }, [message.to_json]] else - preload = preload_json({"/show/#{key}" => message}) - [200, {"Content-Type" => "text/html; charset=utf-8"}, [body(preload)]] + preload = preload_json("/show/#{key}" => message) + [200, { "Content-Type" => "text/html; charset=utf-8" }, [body(preload)]] end elsif resource == "/" - [200, {"Content-Type" => "text/html; charset=utf-8"}, [body(preload_json)]] + [200, { "Content-Type" => "text/html; charset=utf-8" }, [body(preload_json)]] else [404, {}, ["Not found"]] end else @@ -132,12 +132,12 @@ opts = { before: params["before"], after: params["after"] } - if(filter = params["filter"]) - filter = filter.split("_").map{|s| s.to_i} + if (filter = params["filter"]) + filter = filter.split("_").map { |s| s.to_i } opts[:severity] = filter end if search = params["search"] search = (parse_regex(search) || search) if params["regex_search"] == "true" @@ -150,11 +150,11 @@ search: params['search'] || '', filter: filter || '', } json = JSON.generate(payload) - [200, {"Content-Type" => "application/json"}, [json]] + [200, { "Content-Type" => "application/json" }, [json]] end def parse_regex(string) if string =~ /\/(.+)\/(.*)/ s = $1 @@ -167,23 +167,23 @@ if path =~ @path_regex $3 || "/" end end - def preload_json(extra={}) + def preload_json(extra = {}) values = {} values.merge!(extra) end - def css(name, attrs={}) - attrs = attrs.map do |k,v| + def css(name, attrs = {}) + attrs = attrs.map do |k, v| "#{k}='#{v}'" end.join(" ") "<link rel='stylesheet' type='text/css' href='#{@logs_path}/stylesheets/#{name}' #{attrs}>" end - def script(prod, dev=nil) + def script(prod, dev = nil) name = ENV['DEBUG_JS'] == "1" && dev ? dev : prod "<script src='#{@logs_path}/javascript/#{name}'></script>" end def to_json_and_escape(payload)