feature: include other rules

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-06-18 17:32:40 +02:00
parent 243c7b9892
commit 1b36802589

View file

@ -17,6 +17,10 @@ class VulcanoRule < VulcanoBaseRule
VulcanoRule.__send__(m, *a, &b) VulcanoRule.__send__(m, *a, &b)
end end
def self.registry
@rules ||= {}
end
private private
def set_rspec_ids(obj) def set_rspec_ids(obj)
@ -30,5 +34,30 @@ class VulcanoRule < VulcanoBaseRule
end end
def rule id, &block 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 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