diff options
author | Robert Speicher <robert@gitlab.com> | 2017-03-17 00:13:31 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-03-17 00:13:31 +0000 |
commit | 13b1e4fe33f25b5f03a9e3cc164c75ef9a6ad59f (patch) | |
tree | 75bb6720483e38c23132f7a4672cd0b168044948 | |
parent | e5dfcdf26875a2294453cc58d8bbe79f69f37a53 (diff) | |
parent | 871bed7ac0a777d6187cbf09362c5fae441a8607 (diff) | |
download | gitlab-ce-13b1e4fe33f25b5f03a9e3cc164c75ef9a6ad59f.tar.gz |
Merge branch 'dm-use-index-by' into 'master'
Use Enumerable#index_by where possible
See merge request !10011
-rw-r--r-- | app/services/merge_requests/get_urls_service.rb | 5 | ||||
-rw-r--r-- | app/services/users/refresh_authorized_projects_service.rb | 4 | ||||
-rw-r--r-- | lib/banzai/filter/abstract_reference_filter.rb | 7 | ||||
-rw-r--r-- | lib/banzai/filter/user_reference_filter.rb | 5 | ||||
-rw-r--r-- | lib/banzai/reference_parser/base_parser.rb | 4 |
5 files changed, 5 insertions, 20 deletions
diff --git a/app/services/merge_requests/get_urls_service.rb b/app/services/merge_requests/get_urls_service.rb index 1262ecbc29a..ae386b53f42 100644 --- a/app/services/merge_requests/get_urls_service.rb +++ b/app/services/merge_requests/get_urls_service.rb @@ -23,10 +23,7 @@ module MergeRequests def opened_merge_requests_from_source_branches(branches) merge_requests = MergeRequest.from_project(project).opened.from_source_branches(branches) - merge_requests.inject({}) do |hash, mr| - hash[mr.source_branch] = mr - hash - end + merge_requests.index_by(&:source_branch) end def get_branches(changes) diff --git a/app/services/users/refresh_authorized_projects_service.rb b/app/services/users/refresh_authorized_projects_service.rb index d9370bbb598..8f6f5b937c4 100644 --- a/app/services/users/refresh_authorized_projects_service.rb +++ b/app/services/users/refresh_authorized_projects_service.rb @@ -93,9 +93,7 @@ module Users end def current_authorizations_per_project - current_authorizations.each_with_object({}) do |row, hash| - hash[row.project_id] = row - end + current_authorizations.index_by(&:project_id) end def current_authorizations diff --git a/lib/banzai/filter/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb index 02d5ad70fa7..8bc2dd18bda 100644 --- a/lib/banzai/filter/abstract_reference_filter.rb +++ b/lib/banzai/filter/abstract_reference_filter.rb @@ -239,18 +239,13 @@ module Banzai # path. def projects_per_reference @projects_per_reference ||= begin - hash = {} refs = Set.new references_per_project.each do |project_ref, _| refs << project_ref end - find_projects_for_paths(refs.to_a).each do |project| - hash[project.path_with_namespace] = project - end - - hash + find_projects_for_paths(refs.to_a).index_by(&:full_path) end end diff --git a/lib/banzai/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb index 849e1142841..fe1f0923136 100644 --- a/lib/banzai/filter/user_reference_filter.rb +++ b/lib/banzai/filter/user_reference_filter.rb @@ -74,10 +74,7 @@ module Banzai # The keys of this Hash are the namespace paths, the values the # corresponding Namespace objects. def namespaces - @namespaces ||= - Namespace.where_full_path_in(usernames).each_with_object({}) do |row, hash| - hash[row.full_path] = row - end + @namespaces ||= Namespace.where_full_path_in(usernames).index_by(&:full_path) end # Returns all usernames referenced in the current document. diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index b121c37c5d0..52fdb9a2140 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -134,9 +134,7 @@ module Banzai ids = unique_attribute_values(nodes, attribute) rows = collection_objects_for_ids(collection, ids) - rows.each_with_object({}) do |row, hash| - hash[row.id] = row - end + rows.index_by(&:id) end # Returns an Array containing all unique values of an attribute of the |