Fix Style/VerboseBlock issues

This commit is contained in:
syeopite
2021-09-24 19:42:43 -07:00
parent 35d15c7c2b
commit e91421253e
15 changed files with 44 additions and 44 deletions

View File

@@ -89,14 +89,14 @@ def check_table(db, table_name, struct_type = nil)
struct_array = struct_type.type_array
column_array = get_column_array(db, table_name)
column_types = File.read("config/sql/#{table_name}.sql").match(/CREATE TABLE public\.#{table_name}\n\((?<types>[\d\D]*?)\);/)
.try &.["types"].split(",").map { |line| line.strip }.reject &.starts_with?("CONSTRAINT")
.try &.["types"].split(",").map(&.strip).reject &.starts_with?("CONSTRAINT")
return if !column_types
struct_array.each_with_index do |name, i|
if name != column_array[i]?
if !column_array[i]?
new_column = column_types.select { |line| line.starts_with? name }[0]
new_column = column_types.select(&.starts_with?(name))[0]
LOGGER.info("check_table: ALTER TABLE #{table_name} ADD COLUMN #{new_column}")
db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}")
next
@@ -104,14 +104,14 @@ def check_table(db, table_name, struct_type = nil)
# Column doesn't exist
if !column_array.includes? name
new_column = column_types.select { |line| line.starts_with? name }[0]
new_column = column_types.select(&.starts_with?(name))[0]
db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}")
end
# Column exists but in the wrong position, rotate
if struct_array.includes? column_array[i]
until name == column_array[i]
new_column = column_types.select { |line| line.starts_with? column_array[i] }[0]?.try &.gsub("#{column_array[i]}", "#{column_array[i]}_new")
new_column = column_types.select(&.starts_with?(column_array[i]))[0]?.try &.gsub("#{column_array[i]}", "#{column_array[i]}_new")
# There's a column we didn't expect
if !new_column

View File

@@ -173,7 +173,7 @@ module Kemal
return
end
if @cached_files.sum { |element| element[1][:data].bytesize } + (size = File.size(file_path)) < CACHE_LIMIT
if @cached_files.sum(&.[1].[:data].bytesize) + (size = File.size(file_path)) < CACHE_LIMIT
data = Bytes.new(size)
File.open(file_path) do |file|
file.read(data)

View File

@@ -46,7 +46,7 @@ def sign_token(key, hash)
next if key == "signature"
if value.is_a?(JSON::Any) && value.as_a?
value = value.as_a.map { |i| i.as_s }
value = value.as_a.map(&.as_s)
end
case value
@@ -82,7 +82,7 @@ def validate_request(token, session, request, key, db, locale = nil)
raise InfoException.new("Erroneous token")
end
scopes = token["scopes"].as_a.map { |v| v.as_s }
scopes = token["scopes"].as_a.map(&.as_s)
scope = "#{request.method}:#{request.path.lchop("/api/v1/auth/").lstrip("/")}"
if !scopes_include_scope(scopes, scope)
raise InfoException.new("Invalid scope")
@@ -105,11 +105,11 @@ end
def scope_includes_scope(scope, subset)
methods, endpoint = scope.split(":")
methods = methods.split(";").map { |method| method.upcase }.reject { |method| method.empty? }.sort
methods = methods.split(";").map(&.upcase).reject(&.empty?).sort
endpoint = endpoint.downcase
subset_methods, subset_endpoint = subset.split(":")
subset_methods = subset_methods.split(";").map { |method| method.upcase }.sort
subset_methods = subset_methods.split(";").map(&.upcase).sort
subset_endpoint = subset_endpoint.downcase
if methods.empty?