diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 12b3731fe2..17237f3a27 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -128,12 +128,12 @@ class Changeset < ActiveRecord::Base def scan_comment_for_work_package_ids return if comments.blank? # keywords used to reference work packages - ref_keywords = Setting.commit_ref_keywords.downcase.split(',').collect(&:strip) + ref_keywords = Setting.commit_ref_keywords.downcase.split(',').map(&:strip) ref_keywords_any = ref_keywords.delete('*') # keywords used to fix work packages - fix_keywords = Setting.commit_fix_keywords.downcase.split(',').collect(&:strip) + fix_keywords = Setting.commit_fix_keywords.downcase.split(',').map(&:strip) - kw_regexp = (ref_keywords + fix_keywords).collect { |kw| Regexp.escape(kw) }.join('|') + kw_regexp = (ref_keywords + fix_keywords).map { |kw| Regexp.escape(kw) }.join('|') referenced_work_packages = [] diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 5744d98add..650de5b2df 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -139,9 +139,9 @@ class CustomField < ActiveRecord::Base if obj.respond_to?(:project) && obj.project case field_format when 'user' - obj.project.users.sort.collect { |u| [u.to_s, u.id.to_s] } + obj.project.users.sort.map { |u| [u.to_s, u.id.to_s] } when 'version' - obj.project.versions.sort.collect { |u| [u.to_s, u.id.to_s] } + obj.project.versions.sort.map { |u| [u.to_s, u.id.to_s] } end else [] @@ -161,7 +161,7 @@ class CustomField < ActiveRecord::Base def possible_values(obj = nil) case field_format when 'user' - possible_values_options(obj).collect(&:last) + possible_values_options(obj).map(&:last) else options = obj.nil? ? {} : obj read_attribute(:possible_values, options) @@ -171,7 +171,7 @@ class CustomField < ActiveRecord::Base # Makes possible_values accept a multiline string def possible_values=(arg) if arg.is_a?(Array) - value = arg.compact.collect(&:strip).select { |v| !v.blank? } + value = arg.compact.map(&:strip).select { |v| !v.blank? } write_attribute(:possible_values, value, {}) else @@ -258,7 +258,7 @@ class CustomField < ActiveRecord::Base def attribute_locale(attribute, value) locales_for_value = translations.select { |t| t.send(attribute) == value } - .collect(&:locale) + .map(&:locale) .uniq locales_for_value.detect { |l| l == I18n.locale } || locales_for_value.first || I18n.locale @@ -279,7 +279,7 @@ class CustomField::Translation < Globalize::ActiveRecord::Translation def possible_values=(arg) if arg.is_a?(Array) - value = arg.compact.collect(&:strip).select { |v| !v.blank? } + value = arg.compact.map(&:strip).select { |v| !v.blank? } write_attribute(:possible_values, value) else diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 506d7d3cac..66adbf0f96 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -41,7 +41,7 @@ class MailHandler < ActionMailer::Base @@handler_options = options.dup @@handler_options[:issue] ||= {} - @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) if @@handler_options[:allow_override].is_a?(String) + @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').map(&:strip) if @@handler_options[:allow_override].is_a?(String) @@handler_options[:allow_override] ||= [] # Project needs to be overridable if not specified @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project) @@ -121,7 +121,7 @@ class MailHandler < ActionMailer::Base if headers.detect {|h| h.to_s =~ MESSAGE_ID_RE} klass, object_id = $1, $2.to_i method_name = "receive_#{klass}_reply" - if self.class.private_instance_methods.collect(&:to_s).include?(method_name) + if self.class.private_instance_methods.map(&:to_s).include?(method_name) send method_name, object_id else # ignoring it @@ -248,7 +248,7 @@ class MailHandler < ActionMailer::Base def add_watchers(obj) if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project) || user.allowed_to?("add_#{obj.class.lookup_ancestors.last.name.underscore}_watchers".to_sym, obj.project) - addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase} + addresses = [email.to, email.cc].flatten.compact.uniq.map {|a| a.strip.downcase} unless addresses.empty? watchers = User.active.find(:all, conditions: ['LOWER(mail) IN (?)', addresses]) watchers.each {|w| obj.add_watcher(w)} @@ -285,7 +285,7 @@ class MailHandler < ActionMailer::Base keys << all_attribute_translations(Setting.default_language)[attr.to_sym] if Setting.default_language.present? keys.reject! {|k| k.blank?} - keys.collect! {|k| Regexp.escape(k)} + keys.map! {|k| Regexp.escape(k)} format ||= '.+' text.gsub!(/^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i, '') $2 && $2.strip diff --git a/app/models/member.rb b/app/models/member.rb index ce5651c2b1..05edbad963 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -173,7 +173,7 @@ class Member < ActiveRecord::Base ids = roles_or_role_ids.map { |r| (r.is_a? Role) ? r.id : r.to_i } # Keep inherited roles - ids += member_roles.select { |mr| !mr.inherited_from.nil? }.collect(&:role_id) + ids += member_roles.select { |mr| !mr.inherited_from.nil? }.map(&:role_id) new_role_ids = ids - role_ids # Add new roles diff --git a/app/models/project.rb b/app/models/project.rb index 54dbec051f..689ef15d75 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -301,7 +301,7 @@ class Project < ActiveRecord::Base if user && user.admin? return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" elsif user && user.memberships.any? - return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect(&:project_id).join(',')}))" + return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.map(&:project_id).join(',')}))" else return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}" end @@ -337,7 +337,7 @@ class Project < ActiveRecord::Base end user.projects_by_role.each do |role, projects| if role.allowed_to?(permission) - statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.collect(&:id).join(',')})" + statement_by_role[role] = "#{Project.table_name}.id IN (#{projects.map(&:id).join(',')})" end end else @@ -442,7 +442,7 @@ class Project < ActiveRecord::Base def archive # Check that there is no issue of a non descendant project that is assigned # to one of the project or descendant versions - v_ids = self_and_descendants.collect(&:version_ids).flatten + v_ids = self_and_descendants.map(&:version_ids).flatten if v_ids.any? && WorkPackage.find(:first, include: :project, conditions: ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" + " AND #{WorkPackage.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids]) @@ -617,13 +617,13 @@ class Project < ActiveRecord::Base # Returns the mail adresses of users that should be always notified on project events def recipients - notified_users.collect(&:mail) + notified_users.map(&:mail) end # Returns the users that should be notified on project events def notified_users # TODO: User part should be extracted to User#notify_about? - members.select { |m| m.mail_notification? || m.user.mail_notification == 'all' }.collect(&:user) + members.select { |m| m.mail_notification? || m.user.mail_notification == 'all' }.map(&:user) end # Returns an array of all custom fields enabled for project issues @@ -680,8 +680,8 @@ class Project < ActiveRecord::Base def start_date [ work_packages.minimum('start_date'), - shared_versions.collect(&:effective_date), - shared_versions.collect(&:start_date) + shared_versions.map(&:effective_date), + shared_versions.map(&:start_date) ].flatten.compact.min end @@ -689,8 +689,8 @@ class Project < ActiveRecord::Base def due_date [ work_packages.maximum('due_date'), - shared_versions.collect(&:effective_date), - shared_versions.collect { |v| v.fixed_issues.maximum('due_date') } + shared_versions.map(&:effective_date), + shared_versions.map { |v| v.fixed_issues.maximum('due_date') } ].flatten.compact.max end @@ -702,12 +702,12 @@ class Project < ActiveRecord::Base # progress on it's versions. def completed_percent(options = { include_subprojects: false }) if options.delete(:include_subprojects) - total = self_and_descendants.collect(&:completed_percent).sum + total = self_and_descendants.map(&:completed_percent).sum total / self_and_descendants.count else if versions.count > 0 - total = versions.collect(&:completed_percent).sum + total = versions.map(&:completed_percent).sum total / versions.count else @@ -735,8 +735,8 @@ class Project < ActiveRecord::Base def enabled_module_names=(module_names) if module_names && module_names.is_a?(Array) - module_names = module_names.collect(&:to_s).reject(&:blank?) - self.enabled_modules = module_names.collect { |name| enabled_modules.detect { |mod| mod.name == name } || EnabledModule.new(name: name) } + module_names = module_names.map(&:to_s).reject(&:blank?) + self.enabled_modules = module_names.map { |name| enabled_modules.detect { |mod| mod.name == name } || EnabledModule.new(name: name) } else enabled_modules.clear end @@ -744,7 +744,7 @@ class Project < ActiveRecord::Base # Returns an array of the enabled modules names def enabled_module_names - enabled_modules.collect(&:name) + enabled_modules.map(&:name) end safe_attributes 'name', @@ -884,7 +884,7 @@ class Project < ActiveRecord::Base # Returns all the active Systemwide and project specific activities def active_activities - overridden_activity_ids = time_entry_activities.collect(&:parent_id) + overridden_activity_ids = time_entry_activities.map(&:parent_id) if overridden_activity_ids.empty? return TimeEntryActivity.shared.active @@ -896,7 +896,7 @@ class Project < ActiveRecord::Base # Returns all the Systemwide and project specific activities # (inactive and active) def all_activities - overridden_activity_ids = time_entry_activities.collect(&:parent_id) + overridden_activity_ids = time_entry_activities.map(&:parent_id) if overridden_activity_ids.empty? return TimeEntryActivity.shared @@ -910,12 +910,12 @@ class Project < ActiveRecord::Base if include_inactive return TimeEntryActivity.shared .find(:all, - conditions: ['id NOT IN (?)', time_entry_activities.collect(&:parent_id)]) + + conditions: ['id NOT IN (?)', time_entry_activities.map(&:parent_id)]) + time_entry_activities else return TimeEntryActivity.shared.active .find(:all, - conditions: ['id NOT IN (?)', time_entry_activities.collect(&:parent_id)]) + + conditions: ['id NOT IN (?)', time_entry_activities.map(&:parent_id)]) + time_entry_activities.active end end diff --git a/app/models/project/copy.rb b/app/models/project/copy.rb index 436bc75680..34ca504508 100644 --- a/app/models/project/copy.rb +++ b/app/models/project/copy.rb @@ -45,7 +45,7 @@ module Project::Copy with_model(project) do |project| self.enabled_modules = project.enabled_modules self.types = project.types - self.custom_values = project.custom_values.collect(&:clone) + self.custom_values = project.custom_values.map(&:clone) self.work_package_custom_fields = project.work_package_custom_fields end return self @@ -215,7 +215,7 @@ module Project::Copy new_member.send(:assign_attributes, member.attributes.dup.except('id', 'project_id', 'created_on'), without_protection: true) # only copy non inherited roles # inherited roles will be added when copying the group membership - role_ids = member.member_roles.reject(&:inherited?).collect(&:role_id) + role_ids = member.member_roles.reject(&:inherited?).map(&:role_id) next if role_ids.empty? new_member.role_ids = role_ids new_member.project = self diff --git a/app/models/queries/work_packages/available_filter_options.rb b/app/models/queries/work_packages/available_filter_options.rb index babf4e2bd4..a656647134 100644 --- a/app/models/queries/work_packages/available_filter_options.rb +++ b/app/models/queries/work_packages/available_filter_options.rb @@ -85,7 +85,7 @@ module Queries::WorkPackages::AvailableFilterOptions project.principals.sort elsif visible_projects.any? # members of visible projects - principals = Principal.active.where(["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", visible_projects.collect(&:id)]).sort + principals = Principal.active.where(["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", visible_projects.map(&:id)]).sort else [] end @@ -97,9 +97,9 @@ module Queries::WorkPackages::AvailableFilterOptions types = project.nil? ? Type.find(:all, order: 'position') : project.rolled_up_types @available_work_package_filters = { - status_id: { type: :list_status, order: 1, values: Status.all.collect { |s| [s.name, s.id.to_s] } }, - type_id: { type: :list, order: 2, values: types.collect { |s| [s.name, s.id.to_s] } }, - priority_id: { type: :list, order: 3, values: IssuePriority.all.collect { |s| [s.name, s.id.to_s] } }, + status_id: { type: :list_status, order: 1, values: Status.all.map { |s| [s.name, s.id.to_s] } }, + type_id: { type: :list, order: 2, values: types.map { |s| [s.name, s.id.to_s] } }, + priority_id: { type: :list, order: 3, values: IssuePriority.all.map { |s| [s.name, s.id.to_s] } }, subject: { type: :text, order: 8 }, created_at: { type: :date_past, order: 9 }, updated_at: { type: :date_past, order: 10 }, @@ -134,16 +134,16 @@ module Queries::WorkPackages::AvailableFilterOptions # project specific filters categories = project.categories.all unless categories.empty? - @available_work_package_filters['category_id'] = { type: :list_optional, order: 6, values: categories.collect { |s| [s.name, s.id.to_s] } } + @available_work_package_filters['category_id'] = { type: :list_optional, order: 6, values: categories.map { |s| [s.name, s.id.to_s] } } end versions = project.shared_versions.all unless versions.empty? - @available_work_package_filters['fixed_version_id'] = { type: :list_optional, order: 7, values: versions.sort.collect { |s| ["#{s.project.name} - #{s.name}", s.id.to_s] }, name: WorkPackage.human_attribute_name('fixed_version_id') } + @available_work_package_filters['fixed_version_id'] = { type: :list_optional, order: 7, values: versions.sort.map { |s| ["#{s.project.name} - #{s.name}", s.id.to_s] }, name: WorkPackage.human_attribute_name('fixed_version_id') } end unless project.leaf? subprojects = project.descendants.visible.all unless subprojects.empty? - @available_work_package_filters['subproject_id'] = { type: :list_subprojects, order: 13, values: subprojects.collect { |s| [s.name, s.id.to_s] }, name: I18n.t('query_fields.subproject_id') } + @available_work_package_filters['subproject_id'] = { type: :list_subprojects, order: 13, values: subprojects.map { |s| [s.name, s.id.to_s] }, name: I18n.t('query_fields.subproject_id') } end end add_custom_fields_options(project.all_work_package_custom_fields) @@ -153,11 +153,11 @@ module Queries::WorkPackages::AvailableFilterOptions principals_by_class = get_principals.group_by(&:class) user_values = principals_by_class[User].present? ? - principals_by_class[User].collect { |s| [s.name, s.id.to_s] }.sort : + principals_by_class[User].map { |s| [s.name, s.id.to_s] }.sort : [] group_values = Setting.work_package_group_assignment? && principals_by_class[Group].present? ? - principals_by_class[Group].collect { |s| [s.name, s.id.to_s] }.sort : + principals_by_class[Group].map { |s| [s.name, s.id.to_s] }.sort : [] assigned_to_values = (user_values + group_values).sort @@ -169,10 +169,10 @@ module Queries::WorkPackages::AvailableFilterOptions author_values += user_values @available_work_package_filters['author_id'] = { type: :list, order: 5, values: author_values, name: WorkPackage.human_attribute_name('author_id') } unless author_values.empty? - group_values = Group.all.collect { |g| [g.name, g.id.to_s] } + group_values = Group.all.map { |g| [g.name, g.id.to_s] } @available_work_package_filters['member_of_group'] = { type: :list_optional, order: 6, values: group_values, name: I18n.t('query_fields.member_of_group') } unless group_values.empty? - role_values = Role.givable.collect { |r| [r.name, r.id.to_s] } + role_values = Role.givable.map { |r| [r.name, r.id.to_s] } @available_work_package_filters['assigned_to_role'] = { type: :list_optional, order: 7, values: role_values, name: I18n.t('query_fields.assigned_to_role') } unless role_values.empty? responsible_values = user_values.dup @@ -193,7 +193,7 @@ module Queries::WorkPackages::AvailableFilterOptions # global filters for cross project issue list system_shared_versions = Version.visible.find_all_by_sharing('system') unless system_shared_versions.empty? - @available_work_package_filters['fixed_version_id'] = { type: :list_optional, order: 7, values: system_shared_versions.sort.collect { |s| ["#{s.project.name} - #{s.name}", s.id.to_s] }, name: WorkPackage.human_attribute_name('fixed_version_id') } + @available_work_package_filters['fixed_version_id'] = { type: :list_optional, order: 7, values: system_shared_versions.sort.map { |s| ["#{s.project.name} - #{s.name}", s.id.to_s] }, name: WorkPackage.human_attribute_name('fixed_version_id') } end add_custom_fields_options(WorkPackageCustomField.find(:all, conditions: { is_filter: true, is_for_all: true })) end diff --git a/app/models/query.rb b/app/models/query.rb index 282ee6215c..68ab2365f3 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -176,7 +176,7 @@ class Query < ActiveRecord::Base @available_columns += (project ? project.all_work_package_custom_fields : WorkPackageCustomField.find(:all) - ).collect { |cf| ::QueryCustomFieldColumn.new(cf) } + ).map { |cf| ::QueryCustomFieldColumn.new(cf) } if WorkPackage.done_ratio_disabled? @available_columns.select! { |column| column.name != :done_ratio }.length end @@ -212,7 +212,7 @@ class Query < ActiveRecord::Base end else # preserve the column_names order - column_names.collect { |name| available_columns.find { |col| col.name == name } }.compact + column_names.map { |name| available_columns.find { |col| col.name == name } }.compact end end @@ -220,7 +220,7 @@ class Query < ActiveRecord::Base if names.present? names = names.inject([]) { |out, e| out += e.to_s.split(',') } names = names.select { |n| n.is_a?(Symbol) || !n.blank? } - names = names.collect { |n| n.is_a?(Symbol) ? n : n.to_sym } + names = names.map { |n| n.is_a?(Symbol) ? n : n.to_sym } # Set column_names to nil if default columns if names.map(&:to_s) == Setting.work_package_list_default_columns names = nil @@ -240,9 +240,9 @@ class Query < ActiveRecord::Base def sort_criteria=(arg) c = [] if arg.is_a?(Hash) - arg = arg.keys.sort.collect { |k| arg[k] } + arg = arg.keys.sort.map { |k| arg[k] } end - c = arg.select { |k, _o| !k.to_s.blank? }.slice(0, 3).collect { |k, o| [k.to_s, o == 'desc' ? o : 'asc'] } + c = arg.select { |k, _o| !k.to_s.blank? }.slice(0, 3).map { |k, o| [k.to_s, o == 'desc' ? o : 'asc'] } write_attribute(:sort_criteria, c) end @@ -262,7 +262,7 @@ class Query < ActiveRecord::Base def group_by_sort_order if grouped? && (column = group_by_column) column.sortable.is_a?(Array) ? - column.sortable.collect { |s| "#{s} #{column.default_order}" }.join(',') : + column.sortable.map { |s| "#{s} #{column.default_order}" }.join(',') : "#{column.sortable} #{column.default_order}" end end @@ -302,10 +302,10 @@ class Query < ActiveRecord::Base # main project only else # all subprojects - ids += project.descendants.collect(&:id) + ids += project.descendants.map(&:id) end elsif Setting.display_subprojects_work_packages? - ids += project.descendants.collect(&:id) + ids += project.descendants.map(&:id) end project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') elsif project @@ -358,7 +358,7 @@ class Query < ActiveRecord::Base sql_parts << "#{WorkPackage.table_name}.id #{operator == '=' ? 'IN' : 'NOT IN'} (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='WorkPackage' AND #{sql_for_field field, '=', [user_id], db_table, db_field})" end # filter watchers only in projects the user has the permission to view watchers in - project_ids = User.current.projects_by_role.collect { |r, p| p if r.permissions.include? :view_work_package_watchers }.flatten.compact.collect(&:id).uniq + project_ids = User.current.projects_by_role.map { |r, p| p if r.permissions.include? :view_work_package_watchers }.flatten.compact.map(&:id).uniq sql_parts << "#{WorkPackage.table_name}.id #{operator == '=' ? 'IN' : 'NOT IN'} (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='WorkPackage' AND #{sql_for_field field, '=', values, db_table, db_field})"\ " AND #{Project.table_name}.id IN (#{project_ids.join(',')})" unless project_ids.empty? sql << "(#{sql_parts.join(' OR ')})" @@ -379,7 +379,7 @@ class Query < ActiveRecord::Base user_ids << group.user_ids end user_ids.flatten.uniq.compact - }.sort.collect(&:to_s) + }.sort.map(&:to_s) sql << '(' + sql_for_field('assigned_to_id', operator, members_of_groups, WorkPackage.table_name, 'assigned_to_id', false) + ')' @@ -397,13 +397,13 @@ class Query < ActiveRecord::Base members_of_roles = roles.inject([]) {|user_ids, role| if role && role.members user_ids << if project_id - role.members.reject { |m| m.project_id != project_id }.collect(&:user_id) + role.members.reject { |m| m.project_id != project_id }.map(&:user_id) else - role.members.collect(&:user_id) + role.members.map(&:user_id) end end user_ids.flatten.uniq.compact - }.sort.collect(&:to_s) + }.sort.map(&:to_s) sql << '(' + sql_for_field('assigned_to_id', operator, members_of_roles, WorkPackage.table_name, 'assigned_to_id', false) + ')' else @@ -468,14 +468,14 @@ class Query < ActiveRecord::Base sql = "#{db_table}.#{db_field} IS NULL OR " end - sql += "#{db_table}.#{db_field} IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(',') + ')' + sql += "#{db_table}.#{db_field} IN (" + value.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + ')' else # empty set of allowed values produces no result sql = '0=1' end when '!' if value.present? - sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))' + sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))' else # empty set of forbidden values allows all results sql = '1=1' diff --git a/app/models/repository.rb b/app/models/repository.rb index 5261b73ac6..795784a6be 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -168,7 +168,7 @@ class Repository < ActiveRecord::Base changes.find(:all, include: { changeset: :user }, conditions: ['path = ?', path.with_leading_slash], order: "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC", - limit: limit).collect(&:changeset) + limit: limit).map(&:changeset) end end @@ -252,7 +252,7 @@ class Repository < ActiveRecord::Base end def self.available_scm - subclasses.collect { |klass| [klass.scm_name, klass.name] } + subclasses.map { |klass| [klass.scm_name, klass.name] } end def self.factory(klass_name, *args) diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb index 6d1eea5c39..91739c8853 100644 --- a/app/models/repository/subversion.rb +++ b/app/models/repository/subversion.rb @@ -52,7 +52,7 @@ class Repository::Subversion < Repository def latest_changesets(path, rev, limit = 10) revisions = scm.revisions(path, rev, nil, limit: limit) - revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), order: 'committed_on DESC', include: :user) : [] + revisions ? changesets.find_all_by_revision(revisions.map(&:identifier), order: 'committed_on DESC', include: :user) : [] end # Returns a path relative to the url of the repository diff --git a/app/models/role.rb b/app/models/role.rb index ed547fdd35..ab5899be82 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -64,7 +64,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.map { |p| p.to_sym unless p.blank? }.compact.uniq if perms write_attribute(:permissions, perms) end @@ -173,7 +173,7 @@ class Role < ActiveRecord::Base private def allowed_permissions - @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect(&:name) + @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.map(&:name) end def allowed_actions diff --git a/app/models/setting.rb b/app/models/setting.rb index d60118e38c..1d98091f62 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -185,7 +185,7 @@ class Setting < ActiveRecord::Base # Helper that returns an array based on per_page_options setting def self.per_page_options_array - per_page_options.split(%r{[\s,]}).collect(&:to_i).select { |n| n > 0 }.sort + per_page_options.split(%r{[\s,]}).map(&:to_i).select { |n| n > 0 }.sort end # Deprecation Warning: This method is no longer available. There is no diff --git a/app/models/status.rb b/app/models/status.rb index 0447c7d740..002a61d82d 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -70,14 +70,14 @@ class Status < ActiveRecord::Base # Uses association cache when called more than one time def new_statuses_allowed_to(roles, type, author = false, assignee = false) if roles && type - role_ids = roles.collect(&:id) + role_ids = roles.map(&:id) transitions = workflows.select do |w| role_ids.include?(w.role_id) && w.type_id == type.id && (author || !w.author) && (assignee || !w.assignee) end - transitions.collect(&:new_status).uniq.compact.sort + transitions.map(&:new_status).uniq.compact.sort else [] end @@ -87,13 +87,13 @@ class Status < ActiveRecord::Base # More efficient than the previous method if called just once def find_new_statuses_allowed_to(roles, type, author = false, assignee = false) if roles && type - conditions = { role_id: roles.collect(&:id), type_id: type.id } + conditions = { role_id: roles.map(&:id), type_id: type.id } conditions[:author] = false unless author conditions[:assignee] = false unless assignee workflows.find(:all, include: :new_status, - conditions: conditions).collect(&:new_status).compact.sort + conditions: conditions).map(&:new_status).compact.sort else [] end diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 5beaa66c9d..35d867c204 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -114,7 +114,7 @@ class TimeEntry < ActiveRecord::Base def self.earliest_date_for_project(project = nil) finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) if project - finder_conditions << ['project_id IN (?)', project.hierarchy.collect(&:id)] + finder_conditions << ['project_id IN (?)', project.hierarchy.map(&:id)] end TimeEntry.minimum(:spent_on, include: :project, conditions: finder_conditions.conditions) end @@ -122,7 +122,7 @@ class TimeEntry < ActiveRecord::Base def self.latest_date_for_project(project = nil) finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) if project - finder_conditions << ['project_id IN (?)', project.hierarchy.collect(&:id)] + finder_conditions << ['project_id IN (?)', project.hierarchy.map(&:id)] end TimeEntry.maximum(:spent_on, include: :project, conditions: finder_conditions.conditions) end diff --git a/app/models/timeline.rb b/app/models/timeline.rb index ae4ccf037e..758dc68746 100644 --- a/app/models/timeline.rb +++ b/app/models/timeline.rb @@ -341,7 +341,7 @@ class Timeline < ActiveRecord::Base def selected_grouping_projects resolve_with_none_element(:grouping_one_selection) do |ary| projects = Project.find_all_by_id(ary) - projectsHashMap = Hash[projects.collect { |v| [v.id, v] }] + projectsHashMap = Hash[projects.map { |v| [v.id, v] }] ary.map { |a| projectsHashMap[a] } end diff --git a/app/models/type.rb b/app/models/type.rb index 4da92e4fda..d499931297 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -106,7 +106,7 @@ class Type < ActiveRecord::Base end def is_valid_transition?(status_id_a, status_id_b, roles) - transition_exists?(status_id_a, status_id_b, roles.collect(&:id)) + transition_exists?(status_id_a, status_id_b, roles.map(&:id)) end private diff --git a/app/models/user.rb b/app/models/user.rb index aaecfe76e0..a180575ffa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,7 +150,7 @@ class User < Principal validates_format_of :mail, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, allow_blank: true validates_length_of :mail, maximum: 60, allow_nil: true validates_confirmation_of :password, allow_nil: true - validates_inclusion_of :mail_notification, in: MAIL_NOTIFICATION_OPTIONS.collect(&:first), allow_blank: true + validates_inclusion_of :mail_notification, in: MAIL_NOTIFICATION_OPTIONS.map(&:first), allow_blank: true validate :password_meets_requirements @@ -448,7 +448,7 @@ class User < Principal # Return an array of project ids for which the user has explicitly turned mail notifications on def notified_projects_ids - @notified_projects_ids ||= memberships.select(&:mail_notification?).collect(&:project_id) + @notified_projects_ids ||= memberships.select(&:mail_notification?).map(&:project_id) end def notified_project_ids=(ids) @@ -781,7 +781,7 @@ class User < Principal private def initialize_allowance_evaluators - @registered_allowance_evaluators ||= self.class.registered_allowance_evaluators.collect do |evaluator| + @registered_allowance_evaluators ||= self.class.registered_allowance_evaluators.map do |evaluator| evaluator.new(self) end end diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index 7620fb64ae..7a49e1cfa2 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -69,7 +69,7 @@ class WikiContent < ActiveRecord::Base def recipients notified = project.notified_users notified.reject! { |user| !visible?(user) } - notified.collect(&:mail) + notified.map(&:mail) end # FIXME: Deprecate diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index f2a17608c0..40ba1f8701 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -279,7 +279,7 @@ class WikiAnnotate @content = content current = content current_lines = current.journable.text.split(/\r?\n/) - @lines = current_lines.collect { |t| [nil, nil, t] } + @lines = current_lines.map { |t| [nil, nil, t] } positions = [] current_lines.size.times { |i| positions << i } while current.previous diff --git a/app/models/work_package.rb b/app/models/work_package.rb index 96d0b4e0b4..6fb2672712 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -363,14 +363,14 @@ class WorkPackage < ActiveRecord::Base # Returns an array of issues that duplicate this one def duplicates - relations_to.select { |r| r.relation_type == Relation::TYPE_DUPLICATES }.collect(&:from) + relations_to.select { |r| r.relation_type == Relation::TYPE_DUPLICATES }.map(&:from) end def soonest_start @soonest_start ||= ( - self_and_ancestors.collect(&:relations_to) + self_and_ancestors.map(&:relations_to) .flatten - .collect(&:successor_soonest_start) + .map(&:successor_soonest_start) ).compact.max end @@ -493,7 +493,7 @@ class WorkPackage < ActiveRecord::Base notified.uniq! # Remove users that can not view the issue notified.reject! { |user| !visible?(user) } - notified.collect(&:mail) + notified.map(&:mail) end def done_ratio @@ -528,7 +528,7 @@ class WorkPackage < ActiveRecord::Base end if attrs['status_id'] - unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i) + unless new_statuses_allowed_to(user).map(&:id).include?(attrs['status_id'].to_i) attrs.delete('status_id') end end @@ -891,7 +891,7 @@ class WorkPackage < ActiveRecord::Base # Unassigns issues from versions that are no longer shared # after +project+ was moved def self.update_versions_from_hierarchy_change(project) - moved_project_ids = project.self_and_descendants.reload.collect(&:id) + moved_project_ids = project.self_and_descendants.reload.map(&:id) # Update issues of the moved projects and issues assigned to a version of a moved project update_versions(["#{Version.table_name}.project_id IN (?) OR #{WorkPackage.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids]) end @@ -948,7 +948,7 @@ class WorkPackage < ActiveRecord::Base #{WorkPackage.table_name} i, #{Status.table_name} s where i.status_id=s.id - and i.project_id IN (#{project.descendants.active.collect(&:id).join(',')}) + and i.project_id IN (#{project.descendants.active.map(&:id).join(',')}) group by s.id, s.is_closed, i.project_id") if project.descendants.active.any? end # End ReportsController extraction diff --git a/app/models/work_package/pdf_exporter.rb b/app/models/work_package/pdf_exporter.rb index 73bdcc5bda..1f3a395ee9 100644 --- a/app/models/work_package/pdf_exporter.rb +++ b/app/models/work_package/pdf_exporter.rb @@ -65,11 +65,11 @@ module WorkPackage::PdfExporter table_width = page_width - right_margin - 10 # fixed left margin col_width = [] unless query.columns.empty? - col_width = query.columns.collect do |c| + col_width = query.columns.map do |c| (c.name == :subject || (c.is_a?(QueryCustomFieldColumn) && ['string', 'text'].include?(c.custom_field.field_format))) ? 4.0 : 1.0 end ratio = (table_width - col_id_width) / col_width.inject(0) { |s, w| s += w } - col_width = col_width.collect { |w| w * ratio } + col_width = col_width.map { |w| w * ratio } end # title @@ -101,7 +101,7 @@ module WorkPackage::PdfExporter end # fetch all the row values - col_values = query.columns.collect do |column| + col_values = query.columns.map do |column| s = if column.is_a?(QueryCustomFieldColumn) cv = work_package.custom_values.detect { |v| v.custom_field_id == column.custom_field.id } show_value(cv) @@ -428,7 +428,7 @@ module WorkPackage::PdfExporter # 0x5c char handling txtar = txt.split('\\') txtar << '' if txt[-1] == ?\\ - txtar.collect { |x| x.encode(l(:general_pdf_encoding), 'UTF-8') }.join('\\').gsub(/\\/, '\\\\\\\\') + txtar.map { |x| x.encode(l(:general_pdf_encoding), 'UTF-8') }.join('\\').gsub(/\\/, '\\\\\\\\') rescue txt end || '' diff --git a/app/models/workflow.rb b/app/models/workflow.rb index d32fe0a4e6..7ac1df86a8 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -59,8 +59,8 @@ class Workflow < ActiveRecord::Base def self.available_statuses(project, user = User.current) Workflow.find(:all, include: :new_status, - conditions: { role_id: user.roles_for_project(project).collect(&:id) }) - .collect(&:new_status) + conditions: { role_id: user.roles_for_project(project).map(&:id) }) + .map(&:new_status) .compact .uniq .sort