From 8a28b1a730adb96aa8462cf6064627815502f369 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Tue, 4 Nov 2014 11:06:05 +0100 Subject: [PATCH] Prefer #map over #collect in (Rails) controllers Signed-off-by: Alex Coles --- app/controllers/api/v2/workflows_controller.rb | 4 ++-- app/controllers/my_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/controllers/repositories_controller.rb | 10 +++++----- app/controllers/search_controller.rb | 4 ++-- app/controllers/settings_controller.rb | 2 +- app/controllers/time_entries/reports_controller.rb | 4 ++-- app/controllers/versions_controller.rb | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/v2/workflows_controller.rb b/app/controllers/api/v2/workflows_controller.rb index 634e0dae72..af8d22e466 100644 --- a/app/controllers/api/v2/workflows_controller.rb +++ b/app/controllers/api/v2/workflows_controller.rb @@ -44,8 +44,8 @@ module Api accept_key_auth :index def index - workflows = ::Workflow.where(type_id: @project.types.collect(&:id), - role_id: User.current.roles(@project).collect(&:id)) + workflows = ::Workflow.where(type_id: @project.types.map(&:id), + role_id: User.current.roles(@project).map(&:id)) .select(workflow_select_statement) .group('type_id, old_status_id, new_status_id') diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 6cb82d9e82..21fd5089ac 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -195,7 +195,7 @@ class MyController < ApplicationController group = params[:group] @user = User.current if group.is_a?(String) - group_items = (params["list-#{group}"] || []).collect(&:underscore) + group_items = (params["list-#{group}"] || []).map(&:underscore) if group_items and group_items.is_a? Array layout = get_current_layout # remove group blocks if they are presents in other groups diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 78a7faafde..228fabb8f6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -166,7 +166,7 @@ class ProjectsController < ApplicationController if types_missing?(selected_type_ids) flash.delete :notice flash[:error] = I18n.t(:error_types_in_use_by_work_packages, - types: missing_types(selected_type_ids).collect(&:name).join(', ')) + types: missing_types(selected_type_ids).map(&:name).join(', ')) elsif @project.update_attributes(params[:project]) flash[:notice] << l('notice_successful_update') else diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9548cc172c..28b1695117 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -70,7 +70,7 @@ class RepositoriesController < ApplicationController def committers @committers = @repository.committers @users = @project.users - additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) + additional_user_ids = @committers.map(&:last).map(&:to_i) - @users.map(&:id) @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty? @users.compact! @users.sort! @@ -322,16 +322,16 @@ class RepositoriesController < ApplicationController changes_by_author = Change.includes(:changeset).where(["#{Changeset.table_name}.repository_id = ?", repository.id]).group(:committer).size h = changes_by_author.inject({}) { |o, i| o[i.first] = i.last; o } - fields = commits_by_author.collect(&:first) - commits_data = commits_by_author.collect(&:last) - changes_data = commits_by_author.collect { |r| h[r.first] || 0 } + fields = commits_by_author.map(&:first) + commits_data = commits_by_author.map(&:last) + changes_data = commits_by_author.map { |r| h[r.first] || 0 } fields = fields + [''] * (10 - fields.length) if fields.length < 10 commits_data = commits_data + [0] * (10 - commits_data.length) if commits_data.length < 10 changes_data = changes_data + [0] * (10 - changes_data.length) if changes_data.length < 10 # Remove email adress in usernames - fields = fields.collect { |c| c.gsub(%r{<.+@.+>}, '') } + fields = fields.map { |c| c.gsub(%r{<.+@.+>}, '') } graph = SVG::Graph::BarHorizontal.new( height: 400, diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 4f93ddcfa0..23bf3fbf1a 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -43,7 +43,7 @@ class SearchController < ApplicationController when 'all' nil when 'my_projects' - User.current.memberships.collect(&:project) + User.current.memberships.map(&:project) when 'subprojects' @project ? (@project.self_and_descendants.active) : nil else @@ -125,7 +125,7 @@ class SearchController < ApplicationController end def scan_query_tokens(query) - query.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect { |m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '') } + query.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).map { |m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '') } end def scan_work_package_reference(query, &blk) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index df6125854f..18816957e4 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -54,7 +54,7 @@ class SettingsController < ApplicationController redirect_to action: 'edit', tab: params[:tab] else @options = {} - @options[:user_format] = User::USER_FORMATS.keys.collect { |f| [User.current.name(f), f.to_s] } + @options[:user_format] = User::USER_FORMATS.keys.map { |f| [User.current.name(f), f.to_s] } @deliveries = ActionMailer::Base.perform_deliveries @guessed_host = request.host_with_port.dup diff --git a/app/controllers/time_entries/reports_controller.rb b/app/controllers/time_entries/reports_controller.rb index 4378bff841..c17fcf2696 100644 --- a/app/controllers/time_entries/reports_controller.rb +++ b/app/controllers/time_entries/reports_controller.rb @@ -47,8 +47,8 @@ class TimeEntries::ReportsController < ApplicationController retrieve_date_range unless @criterias.empty? - sql_select = @criterias.collect { |criteria| @available_criterias[criteria][:sql] + ' AS ' + criteria }.join(', ') - sql_group_by = @criterias.collect { |criteria| @available_criterias[criteria][:sql] }.join(', ') + sql_select = @criterias.map { |criteria| @available_criterias[criteria][:sql] + ' AS ' + criteria }.join(', ') + sql_group_by = @criterias.map { |criteria| @available_criterias[criteria][:sql] }.join(', ') sql_condition = '' if @project.nil? diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index b27d03d767..4a3994a5e9 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -41,7 +41,7 @@ class VersionsController < ApplicationController @types = @project.types.find(:all, order: 'position') retrieve_selected_type_ids(@types, @types.select(&:is_in_roadmap?)) @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_work_packages? : (params[:with_subprojects].to_i == 1) - project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] + project_ids = @with_subprojects ? @project.self_and_descendants.map(&:id) : [@project.id] @versions = @project.shared_versions || [] @versions += @project.rolled_up_versions.visible if @with_subprojects @@ -164,9 +164,9 @@ class VersionsController < ApplicationController def retrieve_selected_type_ids(selectable_types, default_types = nil) if ids = params[:type_ids] - @selected_type_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } + @selected_type_ids = (ids.is_a? Array) ? ids.map { |id| id.to_i.to_s } : ids.split('/').map { |id| id.to_i.to_s } else - @selected_type_ids = (default_types || selectable_types).collect { |t| t.id.to_s } + @selected_type_ids = (default_types || selectable_types).map { |t| t.id.to_s } end end end