summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-01-17 01:38:27 +0000
committerGo MAEDA <maeda@farend.jp>2023-01-17 01:38:27 +0000
commit0b6f4c6811a4a4e823674e3bb8b970ee46a9194b (patch)
tree341119beb1c247727c68ba9913a7a2bfc3fa3006 /app
parent97d07eb28573060085352e0e9046be16e29f5bfd (diff)
downloadredmine-0b6f4c6811a4a4e823674e3bb8b970ee46a9194b.tar.gz
redmine-0b6f4c6811a4a4e823674e3bb8b970ee46a9194b.zip
Ruby 2.7: Fix RuboCop offense Performance/MapCompact (#38134).
git-svn-id: https://svn.redmine.org/redmine/trunk@22055 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/context_menus_controller.rb2
-rw-r--r--app/controllers/timelog_controller.rb2
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/issue_relations_helper.rb2
-rw-r--r--app/helpers/members_helper.rb4
-rw-r--r--app/helpers/queries_helper.rb4
-rw-r--r--app/helpers/repositories_helper.rb4
-rw-r--r--app/models/member.rb3
-rw-r--r--app/models/query.rb4
-rw-r--r--app/models/repository.rb2
-rw-r--r--app/models/repository/git.rb2
-rw-r--r--app/models/repository/mercurial.rb4
-rw-r--r--app/models/repository/subversion.rb4
-rw-r--r--app/models/role.rb2
15 files changed, 21 insertions, 22 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 4382bb3bc..6bda01088 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -405,7 +405,7 @@ class ApplicationController < ActionController::Base
raise ActiveRecord::RecordNotFound if @issues.empty?
raise Unauthorized unless @issues.all?(&:visible?)
- @projects = @issues.collect(&:project).compact.uniq
+ @projects = @issues.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
rescue ActiveRecord::RecordNotFound
render_404
diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb
index 848e8de2a..b3f775156 100644
--- a/app/controllers/context_menus_controller.rb
+++ b/app/controllers/context_menus_controller.rb
@@ -74,7 +74,7 @@ class ContextMenusController < ApplicationController
@time_entry = @time_entries.first
end
- @projects = @time_entries.collect(&:project).compact.uniq
+ @projects = @time_entries.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
@activities = @projects.map(&:activities).reduce(:&)
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 46c278664..d4caca0f6 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -280,7 +280,7 @@ class TimelogController < ApplicationController
raise ActiveRecord::RecordNotFound if @time_entries.empty?
raise Unauthorized unless @time_entries.all? {|t| t.editable_by?(User.current)}
- @projects = @time_entries.collect(&:project).compact.uniq
+ @projects = @time_entries.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
rescue ActiveRecord::RecordNotFound
render_404
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 72d9d8efd..43f32fbc7 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1503,7 +1503,7 @@ module ApplicationHelper
# Render the error messages for the given objects
def error_messages_for(*objects)
- objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
+ objects = objects.filter_map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}
errors = objects.map {|o| o.errors.full_messages}.flatten
render_error_messages(errors)
end
diff --git a/app/helpers/issue_relations_helper.rb b/app/helpers/issue_relations_helper.rb
index 02ff9d427..4323ea730 100644
--- a/app/helpers/issue_relations_helper.rb
+++ b/app/helpers/issue_relations_helper.rb
@@ -33,7 +33,7 @@ module IssueRelationsHelper
end
messages.map do |message, items|
- ids = items.map(&:issue_to_id).compact
+ ids = items.filter_map(&:issue_to_id)
if ids.empty?
message
else
diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb
index e7e2e09e0..0e542768c 100644
--- a/app/helpers/members_helper.rb
+++ b/app/helpers/members_helper.rb
@@ -50,13 +50,13 @@ module MembersHelper
# Returns inheritance information for an inherited member role
def render_role_inheritance(member, role)
- content = member.role_inheritance(role).map do |h|
+ content = member.role_inheritance(role).filter_map do |h|
if h.is_a?(Project)
l(:label_inherited_from_parent_project)
elsif h.is_a?(Group)
l(:label_inherited_from_group, :name => h.name.to_s)
end
- end.compact.uniq
+ end.uniq
if content.present?
content_tag('em', content.join(", "), :class => "info")
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 86b647b83..d40ee2587 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -233,7 +233,7 @@ module QueriesHelper
value = column.value_object(item)
content =
if value.is_a?(Array)
- values = value.collect {|v| column_value(column, item, v)}.compact
+ values = value.filter_map {|v| column_value(column, item, v)}
safe_join(values, ', ')
else
column_value(column, item, value)
@@ -286,7 +286,7 @@ module QueriesHelper
def csv_content(column, item)
value = column.value_object(item)
if value.is_a?(Array)
- value.collect {|v| csv_value(column, item, v)}.compact.join(', ')
+ value.filter_map {|v| csv_value(column, item, v)}.join(', ')
else
csv_value(column, item, value)
end
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index 2a338799e..719761265 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -52,7 +52,7 @@ module RepositoriesHelper
end
def render_changeset_changes
- changes = @changeset.filechanges.limit(1000).reorder('path').collect do |change|
+ changes = @changeset.filechanges.limit(1000).reorder('path').filter_map do |change|
case change.action
when 'A'
# Detects moved/copied files
@@ -66,7 +66,7 @@ module RepositoriesHelper
else
change
end
- end.compact
+ end
tree = {}
changes.each do |change|
diff --git a/app/models/member.rb b/app/models/member.rb
index 46a81afc0..21c623408 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -120,8 +120,7 @@ class Member < ActiveRecord::Base
def role_inheritance(role)
member_roles.
select {|mr| mr.role_id == role.id && mr.inherited_from.present?}.
- map {|mr| mr.inherited_from_member_role.try(:member)}.
- compact.
+ filter_map {|mr| mr.inherited_from_member_role.try(:member)}.
map {|m| m.project == project ? m.principal : m.project}
end
diff --git a/app/models/query.rb b/app/models/query.rb
index e25824bd0..bd670205b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -787,9 +787,9 @@ class Query < ActiveRecord::Base
return [] if available_columns.empty?
# preserve the column_names order
- cols = (has_default_columns? ? default_columns_names : column_names).collect do |name|
+ cols = (has_default_columns? ? default_columns_names : column_names).filter_map do |name|
available_columns.find {|col| col.name == name}
- end.compact
+ end
available_columns.select(&:frozen?) | cols
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index dc7783aff..be10fa3cf 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -436,7 +436,7 @@ class Repository < ActiveRecord::Base
# commits.to_a.sort! {|x, y| x.last <=> y.last}
changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).
select("committer, user_id, count(*) as count").group("committer, user_id")
- user_ids = changesets.map(&:user_id).compact.uniq
+ user_ids = changesets.filter_map(&:user_id).uniq
authors_names = User.where(:id => user_ids).inject({}) do |memo, user|
memo[user.id] = user.to_s
memo
diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb
index 2463ab80a..2c77c173d 100644
--- a/app/models/repository/git.rb
+++ b/app/models/repository/git.rb
@@ -213,7 +213,7 @@ class Repository::Git < Repository
private :save_revisions
def save_revision(rev)
- parents = (rev.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact
+ parents = (rev.parents || []).filter_map{|rp| find_changeset_by_name(rp)}
changeset =
Changeset.create(
:repository => self,
diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb
index 30cd59fd5..a152950c9 100644
--- a/app/models/repository/mercurial.rb
+++ b/app/models/repository/mercurial.rb
@@ -193,9 +193,9 @@ class Repository::Mercurial < Repository
(db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
transaction do
- parents = (re.parents || []).collect do |rp|
+ parents = (re.parents || []).filter_map do |rp|
find_changeset_by_name(scmid_for_inserting_db(rp))
- end.compact
+ end
cs = Changeset.create(:repository => self,
:revision => re.revision,
:scmid => scmid_for_inserting_db(re.scmid),
diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb
index c6355cff1..373d250bc 100644
--- a/app/models/repository/subversion.rb
+++ b/app/models/repository/subversion.rb
@@ -42,7 +42,7 @@ class Repository::Subversion < Repository
def latest_changesets(path, rev, limit=10)
revisions = scm.revisions(path, rev, nil, :limit => limit)
if revisions
- identifiers = revisions.collect(&:identifier).compact
+ identifiers = revisions.filter_map(&:identifier)
changesets.where(:revision => identifiers).reorder("committed_on DESC").includes(:repository, :user).to_a
else
[]
@@ -97,7 +97,7 @@ class Repository::Subversion < Repository
entries_with_identifier =
entries.select {|entry| entry.lastrev && entry.lastrev.identifier.present?}
- identifiers = entries_with_identifier.map {|entry| entry.lastrev.identifier}.compact.uniq
+ identifiers = entries_with_identifier.filter_map {|entry| entry.lastrev.identifier}.uniq
if identifiers.any?
changesets_by_identifier =
changesets.where(:revision => identifiers).
diff --git a/app/models/role.rb b/app/models/role.rb
index b73f97d4c..e67f30054 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -122,7 +122,7 @@ class Role < ActiveRecord::Base
end
def permissions=(perms)
- perms = perms.collect {|p| p.to_sym unless p.blank?}.compact.uniq if perms
+ perms = perms.filter_map {|p| p.to_sym unless p.blank?}.uniq if perms
write_attribute(:permissions, perms)
end