From 871bed7ac0a777d6187cbf09362c5fae441a8607 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 16 Mar 2017 09:22:09 -0600 Subject: Use Enumerable#index_by where possible --- lib/banzai/filter/abstract_reference_filter.rb | 7 +------ lib/banzai/filter/user_reference_filter.rb | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) (limited to 'lib/banzai/filter') 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. -- cgit v1.2.1