From: Tom Clegg Date: Mon, 10 Oct 2016 17:45:11 +0000 (-0400) Subject: 5737: Avoid redefining recursive_hash_search() on each use X-Git-Tag: 1.1.0~571^2~25 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/b8a539e3a0803083b1fcbb23755fc12cffff6f31 5737: Avoid redefining recursive_hash_search() on each use --- diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb index 30ca7f8cb2..1c4742500f 100644 --- a/services/api/app/models/job.rb +++ b/services/api/app/models/job.rb @@ -565,24 +565,6 @@ class Job < ArvadosModel end def ensure_no_collection_uuids_in_script_params - # recursive_hash_search searches recursively through hashes and - # arrays in 'thing' for string fields matching regular expression - # 'pattern'. Returns true if pattern is found, false otherwise. - def recursive_hash_search thing, pattern - if thing.is_a? Hash - thing.each do |k, v| - return true if recursive_hash_search v, pattern - end - elsif thing.is_a? Array - thing.each do |k| - return true if recursive_hash_search k, pattern - end - elsif thing.is_a? String - return true if thing.match pattern - end - false - end - # Fail validation if any script_parameters field includes a string containing a # collection uuid pattern. if self.script_parameters_changed? @@ -593,4 +575,22 @@ class Job < ArvadosModel end true end + + # recursive_hash_search searches recursively through hashes and + # arrays in 'thing' for string fields matching regular expression + # 'pattern'. Returns true if pattern is found, false otherwise. + def recursive_hash_search thing, pattern + if thing.is_a? Hash + thing.each do |k, v| + return true if recursive_hash_search v, pattern + end + elsif thing.is_a? Array + thing.each do |k| + return true if recursive_hash_search k, pattern + end + elsif thing.is_a? String + return true if thing.match pattern + end + false + end end