From cecd86a1199153a4bd797f39dae7e7362b701238 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 12 Aug 2015 17:29:23 -0700 Subject: [PATCH] improvement: unify ID generation for all tests Signed-off-by: Dominik Richter --- lib/verify/specfile.rb | 14 ++++++++------ lib/vulcano/base_rule.rb | 26 +++++++++++++++++--------- lib/vulcano/rule.rb | 4 ++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/verify/specfile.rb b/lib/verify/specfile.rb index cc2ddbd17..01c3bc112 100644 --- a/lib/verify/specfile.rb +++ b/lib/verify/specfile.rb @@ -39,17 +39,19 @@ module Vulcano src = __get_block_source(&r.instance_variable_get(:@__block)) end r.instance_variable_set(:@__code, src) - fid = VulcanoBaseRule.full_id r, @profile_id - if @rules[fid].nil? - @rules[fid] = r + + full_id = VulcanoBaseRule.full_id @profile_id, r + if @rules[full_id].nil? + @rules[full_id] = r else @errors.push "Duplicate definition of rule #{fid}." end end + def __unregister_rule id - fid = "#{@profile_id}/#{id}" - if @rules.key? fid - @rules.delete(fid) + full_id = VulcanoBaseRule.full_id @profile_id, id + if @rules.key?(full_id) + @rules.delete(full_id) else @errors.push "Failed to skip rule #{fid}, it isn't defined." end diff --git a/lib/vulcano/base_rule.rb b/lib/vulcano/base_rule.rb index 9069eafd0..8082c74e7 100644 --- a/lib/vulcano/base_rule.rb +++ b/lib/vulcano/base_rule.rb @@ -65,20 +65,28 @@ class VulcanoBaseRule # for the rule. If the rule's profile id is empty, # the given profile_id will be used instead and also # set for the rule. - def self.full_id rule, profile_id - # As the profile context is exclusively pulled with a - # profile ID, attach it to the rule if necessary. - rid = rule.instance_variable_get(:@id) - if rid.nil? - # TODO: Message about skipping this rule - # due to missing ID - return nil + def self.full_id profile_id, rule + if rule.is_a?(String) or rule.nil? + rid = rule + else + # As the profile context is exclusively pulled with a + # profile ID, attach it to the rule if necessary. + rid = rule.instance_variable_get(:@id) + if rid.nil? + # TODO: Message about skipping this rule + # due to missing ID + return nil + end end pid = rule.instance_variable_get(:@profile_id) if pid.nil? rule.instance_variable_set(:@profile_id, profile_id) pid = profile_id end - return (pid || '') + "/" + rid + if pid.nil? or pid.empty? + return rid + else + return "#{pid}/#{rid}" + end end end diff --git a/lib/vulcano/rule.rb b/lib/vulcano/rule.rb index 6cc0494a7..8788d71fa 100644 --- a/lib/vulcano/rule.rb +++ b/lib/vulcano/rule.rb @@ -191,13 +191,13 @@ module Vulcano end def __unregister_rule id - full_id = "#{@profile_id}/#{id}" + full_id = VulcanoBaseRule::full_id(@profile_id, id) @rules[full_id] = nil end def __register_rule r # get the full ID - full_id = VulcanoBaseRule::full_id(r, @profile_id) + full_id = VulcanoBaseRule::full_id(@profile_id, r) if full_id.nil? # TODO error return