diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-23 06:09:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-23 06:09:49 +0300 |
commit | 163b6c3c80c2aad98d0eedb3ccd76a72c5e72771 (patch) | |
tree | 68f939d4ea170754d063979501548259560b0236 /qa | |
parent | 5d3bcd82b5d6a8567c3c0b1d1620fdd26a4513c5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/resource/base.rb | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb index 2848e3ba7d2..a7243b7ebc2 100644 --- a/qa/qa/resource/base.rb +++ b/qa/qa/resource/base.rb @@ -100,7 +100,9 @@ module QA attr_writer(name) define_method(name) do - instance_variable_get("@#{name}") || instance_variable_set("@#{name}", populate_attribute(name, block)) + return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}") + + instance_variable_set("@#{name}", attribute_value(name, block)) end end @@ -121,9 +123,7 @@ module QA return self unless api_resource all_attributes.each do |attribute_name| - api_value = api_resource[attribute_name] - - instance_variable_set("@#{attribute_name}", api_value) if api_value + instance_variable_set("@#{attribute_name}", api_resource[attribute_name]) if api_resource.key?(attribute_name) end self @@ -160,20 +160,17 @@ module QA private - def populate_attribute(name, block) - value = attribute_value(name, block) - - raise NoValueError, "No value was computed for #{name} of #{self.class.name}." unless value - - value - end - def attribute_value(name, block) - api_value = api_resource&.dig(name) + no_api_value = !api_resource&.key?(name) + raise NoValueError, "No value was computed for #{name} of #{self.class.name}." if no_api_value && !block - log_having_both_api_result_and_block(name, api_value) if api_value && block + unless no_api_value + api_value = api_resource[name] + log_having_both_api_result_and_block(name, api_value) if block + return api_value + end - api_value || (block && instance_exec(&block)) + instance_exec(&block) end # Get all defined attributes across all parents |