improvement: unify ID generation for all tests

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-12 17:29:23 -07:00
parent 7f67a088cb
commit cecd86a119
3 changed files with 27 additions and 17 deletions

View file

@ -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

View file

@ -65,7 +65,10 @@ 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
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)
@ -74,11 +77,16 @@ class VulcanoBaseRule
# 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

View file

@ -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