From 1b36802589923b317937e66da52310fd0e1ccb12 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 18 Jun 2015 17:32:40 +0200 Subject: [PATCH] feature: include other rules Signed-off-by: Dominik Richter --- lib/vulcano/rule.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/vulcano/rule.rb b/lib/vulcano/rule.rb index 8a62d81fe..d85ddc375 100644 --- a/lib/vulcano/rule.rb +++ b/lib/vulcano/rule.rb @@ -17,6 +17,10 @@ class VulcanoRule < VulcanoBaseRule VulcanoRule.__send__(m, *a, &b) end + def self.registry + @rules ||= {} + end + private def set_rspec_ids(obj) @@ -30,5 +34,30 @@ class VulcanoRule < VulcanoBaseRule end def rule id, &block - VulcanoRule.new(id, &block) + existing = VulcanoRule.registry[id] + if existing.nil? + VulcanoRule.registry[id] = VulcanoRule.new(id, &block) + else + # TODO: alter existing rule + end end + + +def include_rules id + base_path = '/etc/vulcanosec/tests' + path = File.join( base_path, id ) + # find all files to be included + files = [] + if File::directory? path + # include all library paths, if they exist + libdir = File::join(path, 'lib') + if File::directory? libdir and !$LOAD_PATH.include?(libdir) + $LOAD_PATH.unshift(libdir) + end + files = Dir[File.join(path, 'spec','*_spec.rb')] + end + # include all files + files.each do |file| + eval(File::read(file)) + end +end \ No newline at end of file