Add rubocop to our build. (#5004)

This commit is contained in:
Guo Xiang Tan
2017-07-28 10:20:09 +09:00
committed by GitHub
parent ff4e295c4f
commit 5012d46cbd
871 changed files with 5480 additions and 6056 deletions

View File

@ -30,9 +30,9 @@ module Middleware
# don't initialize params until later otherwise
# you get a broken params on the request
params = {}
user_agent = @env[USER_AGENT]
user_agent = @env[USER_AGENT]
MobileDetection.resolve_mobile_view!(user_agent,params,session) ? :true : :false
MobileDetection.resolve_mobile_view!(user_agent, params, session) ? :true : :false
end
@is_mobile == :true
@ -49,7 +49,7 @@ module Middleware
def is_crawler?
@is_crawler ||=
begin
user_agent = @env[USER_AGENT]
user_agent = @env[USER_AGENT]
CrawlerDetection.crawler?(user_agent) ? :true : :false
end
@is_crawler == :true
@ -60,7 +60,7 @@ module Middleware
end
def theme_key
key,_ = @request.cookies['theme_key']&.split(',')
key, _ = @request.cookies['theme_key']&.split(',')
if key && Guardian.new.allow_theme?(key)
key
else
@ -110,10 +110,10 @@ module Middleware
# that fills it up, this avoids a herd killing you, we can probably do this using a job or redis tricks
# but coordinating this is tricky
def cache(result)
status,headers,response = result
status, headers, response = result
if status == 200 && cache_duration
headers_stripped = headers.dup.delete_if{|k, _| ["Set-Cookie","X-MiniProfiler-Ids"].include? k}
headers_stripped = headers.dup.delete_if { |k, _| ["Set-Cookie", "X-MiniProfiler-Ids"].include? k }
headers_stripped["X-Discourse-Cached"] = "true"
parts = []
response.each do |part|
@ -121,12 +121,12 @@ module Middleware
end
$redis.setex(cache_key_body, cache_duration, parts.join)
$redis.setex(cache_key_other, cache_duration, [status,headers_stripped].to_json)
$redis.setex(cache_key_other, cache_duration, [status, headers_stripped].to_json)
else
parts = response
end
[status,headers,parts]
[status, headers, parts]
end
def clear_cache
@ -136,7 +136,7 @@ module Middleware
end
def initialize(app, settings={})
def initialize(app, settings = {})
@app = app
end
@ -144,7 +144,7 @@ module Middleware
helper = Helper.new(env)
if helper.cacheable?
helper.cached or helper.cache(@app.call(env))
helper.cached || helper.cache(@app.call(env))
else
@app.call(env)
end