Prefer #map over #collect in (Rails) controllers

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/2136/head
Alex Coles 10 years ago
parent 25ede2df34
commit 8a28b1a730
  1. 4
      app/controllers/api/v2/workflows_controller.rb
  2. 2
      app/controllers/my_controller.rb
  3. 2
      app/controllers/projects_controller.rb
  4. 10
      app/controllers/repositories_controller.rb
  5. 4
      app/controllers/search_controller.rb
  6. 2
      app/controllers/settings_controller.rb
  7. 4
      app/controllers/time_entries/reports_controller.rb
  8. 6
      app/controllers/versions_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')

@ -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

@ -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

@ -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,

@ -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)

@ -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

@ -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?

@ -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

Loading…
Cancel
Save