From 10db502ac06ae4566895cf2b5ffdf52db94181eb Mon Sep 17 00:00:00 2001 From: radhika Date: Tue, 11 Oct 2016 10:46:45 -0400 Subject: [PATCH] 10144: Rename :by_name as "by_attr" for preload_objects_for_dataclass --- .../app/controllers/application_controller.rb | 10 ++++++---- .../app/views/work_units/_component_detail.html.erb | 2 +- .../app/views/work_units/_show_component.html.erb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index d0ecfe9af1..d8dc852ca2 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -1180,15 +1180,15 @@ class ApplicationController < ActionController::Base # helper method to get object of a given dataclass and uuid helper_method :object_for_dataclass - def object_for_dataclass dataclass, uuid, by_name=nil + def object_for_dataclass dataclass, uuid, by_attr=nil raise ArgumentError, 'No input argument dataclass' unless (dataclass && uuid) - preload_objects_for_dataclass(dataclass, [uuid], by_name) + preload_objects_for_dataclass(dataclass, [uuid], by_attr) @objects_for[uuid] end # helper method to preload objects for given dataclass and uuids helper_method :preload_objects_for_dataclass - def preload_objects_for_dataclass dataclass, uuids, by_name=nil + def preload_objects_for_dataclass dataclass, uuids, by_attr=nil @objects_for ||= {} raise ArgumentError, 'Argument is not a data class' unless dataclass.is_a? Class @@ -1205,7 +1205,9 @@ class ApplicationController < ActionController::Base uuids.each do |x| @objects_for[x] = nil end - if by_name + if by_attr and ![:uuid, :name].include?(by_attr) + raise ArgumentError, "Preloading only using lookups by uuid or name are supported: #{by_attr}" + elsif by_attr and by_attr == :name dataclass.where(name: uuids).each do |obj| @objects_for[obj.name] = obj end diff --git a/apps/workbench/app/views/work_units/_component_detail.html.erb b/apps/workbench/app/views/work_units/_component_detail.html.erb index 45ae978692..f66ff07a88 100644 --- a/apps/workbench/app/views/work_units/_component_detail.html.erb +++ b/apps/workbench/app/views/work_units/_component_detail.html.erb @@ -43,7 +43,7 @@ <% # link to repo tree/file only if the repo is readable and the commit is a sha1 repo = (/^[0-9a-f]{40}$/ =~ current_obj.script_version and - object_for_dataclass(Repository, current_obj.repository, :by_name)) + object_for_dataclass(Repository, current_obj.repository, :name)) repo = nil unless repo.andand.http_fetch_url %> <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic, diff --git a/apps/workbench/app/views/work_units/_show_component.html.erb b/apps/workbench/app/views/work_units/_show_component.html.erb index 9bf751f70c..08405b305a 100644 --- a/apps/workbench/app/views/work_units/_show_component.html.erb +++ b/apps/workbench/app/views/work_units/_show_component.html.erb @@ -68,7 +68,7 @@ end repos = wu.children.collect {|c| c.repository}.uniq.compact - preload_objects_for_dataclass(Repository, repos, :by_name) if repos.any? + preload_objects_for_dataclass(Repository, repos, :name) if repos.any? %> <% if wu.has_unreadable_children %> -- 2.30.2