2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

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

@ -1,13 +1,13 @@
class SqlBuilder
def initialize(template,klass=nil)
def initialize(template, klass = nil)
@args = {}
@sql = template
@sections = {}
@klass = klass
end
[:set, :where2,:where,:order_by,:limit,:left_join,:join,:offset, :select].each do |k|
[:set, :where2, :where, :order_by, :limit, :left_join, :join, :offset, :select].each do |k|
define_method k do |data, args = {}|
@args.merge!(args)
@sections[k] ||= []
@ -18,7 +18,7 @@ class SqlBuilder
def secure_category(secure_category_ids, category_alias = 'c')
if secure_category_ids.present?
where("NOT COALESCE(" << category_alias << ".read_restricted, false) OR " << category_alias << ".id IN (:secure_category_ids)", secure_category_ids: secure_category_ids)
where("NOT COALESCE(" << category_alias << ".read_restricted, false) OR " << category_alias << ".id IN (:secure_category_ids)", secure_category_ids: secure_category_ids)
else
where("NOT COALESCE(" << category_alias << ".read_restricted, false)")
end
@ -28,17 +28,17 @@ class SqlBuilder
def to_sql
sql = @sql.dup
@sections.each do |k,v|
@sections.each do |k, v|
joined = nil
case k
when :select
joined = "SELECT " << v.join(" , ")
when :where, :where2
joined = "WHERE " << v.map{|c| "(" << c << ")" }.join(" AND ")
joined = "WHERE " << v.map { |c| "(" << c << ")" }.join(" AND ")
when :join
joined = v.map{|item| "JOIN " << item }.join("\n")
joined = v.map { |item| "JOIN " << item }.join("\n")
when :left_join
joined = v.map{|item| "LEFT JOIN " << item }.join("\n")
joined = v.map { |item| "LEFT JOIN " << item }.join("\n")
when :limit
joined = "LIMIT " << v.last.to_s
when :offset
@ -64,7 +64,7 @@ class SqlBuilder
if @args == {}
ActiveRecord::Base.exec_sql(sql)
else
ActiveRecord::Base.exec_sql(sql,@args)
ActiveRecord::Base.exec_sql(sql, @args)
end
end
end
@ -74,7 +74,7 @@ class SqlBuilder
end
class RailsDateTimeDecoder < PG::SimpleDecoder
def decode(string, tuple=nil, field=nil)
def decode(string, tuple = nil, field = nil)
if Rails.version >= "4.2.0"
@caster ||= ActiveRecord::Type::DateTime.new
@caster.type_cast_from_database(string)
@ -84,14 +84,13 @@ class SqlBuilder
end
end
class ActiveRecordTypeMap < PG::BasicTypeMapForResults
def initialize(connection)
super(connection)
rm_coder 0, 1114
add_coder RailsDateTimeDecoder.new(name: "timestamp", oid: 1114, format: 0)
# we don't need deprecations
self.default_type_map = PG::TypeMapInRuby.new
# we don't need deprecations
self.default_type_map = PG::TypeMapInRuby.new
end
end