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

View File

@@ -5,19 +5,19 @@ module Middleware
# due to the files not being present locally. This middleware, only enabled in development
# mode, will replace those with an appropriate image.
class MissingAvatars
def initialize(app, settings={})
def initialize(app, settings = {})
@app = app
end
def call(env)
if (env['REQUEST_PATH'] =~ /^\/uploads\/default\/avatars/)
path = "#{Rails.root}/public#{env['REQUEST_PATH']}"
unless File.exist?(path)
unless File.exist?(path)
default_image = "#{Rails.root}/public/images/d-logo-sketch-small.png"
return [ 200, { 'Content-Type' => 'image/png' }, [ File.read(default_image)] ]
end
end
status, headers, response = @app.call(env)
[status, headers, response]
end

View File

@@ -2,11 +2,11 @@ require_dependency 'middleware/anonymous_cache'
class Middleware::RequestTracker
def initialize(app, settings={})
def initialize(app, settings = {})
@app = app
end
def self.log_request_on_site(data,host)
def self.log_request_on_site(data, host)
RailsMultisite::ConnectionManagement.with_hostname(host) do
log_request(data)
end
@@ -46,8 +46,8 @@ class Middleware::RequestTracker
TRACK_VIEW = "HTTP_DISCOURSE_TRACK_VIEW".freeze
CONTENT_TYPE = "Content-Type".freeze
def self.get_data(env,result)
status,headers = result
def self.get_data(env, result)
status, headers = result
status = status.to_i
helper = Middleware::AnonymousCache::Helper.new(env)
@@ -74,21 +74,21 @@ class Middleware::RequestTracker
ensure
# we got to skip this on error ... its just logging
data = self.class.get_data(env,result) rescue nil
data = self.class.get_data(env, result) rescue nil
host = RailsMultisite::ConnectionManagement.host(env)
if data
if result && (headers=result[1])
if result && (headers = result[1])
headers["X-Discourse-TrackView"] = "1" if data[:track_view]
end
log_later(data,host)
log_later(data, host)
end
end
def log_later(data,host)
Scheduler::Defer.later("Track view", _db=nil) do
self.class.log_request_on_site(data,host)
def log_later(data, host)
Scheduler::Defer.later("Track view", _db = nil) do
self.class.log_request_on_site(data, host)
end
end

View File

@@ -13,7 +13,7 @@ module Middleware
# config.middleware.insert 0, Middleware::TurboDev
#
class TurboDev
def initialize(app, settings={})
def initialize(app, settings = {})
@app = app
end
@@ -27,7 +27,7 @@ module Middleware
etag = etag.gsub "\"", ""
asset = Rails.application.assets.find_asset(name)
if asset && asset.digest == etag
return [304,{},[]]
return [304, {}, []]
end
end