move DSL helper methods out of local DSL space

to avoid potential collissions

Signed-off-by: Dominik Richter <dominik@vulcanosec.com>
This commit is contained in:
Dominik Richter 2015-06-19 21:43:04 +02:00
parent 8181ee038e
commit da71e1e826

View file

@ -26,54 +26,26 @@ module Vulcano
end end
end end
# class Rule < ::Vulcano::Rule
# def describe(sth, &block)
# @examples ||= []
# @examples.push([sth, block])
# end
# end
module Vulcano::DSL module Vulcano::DSL
def rule id, &block def rule id, &block
r = Vulcano::Rule.new(id, &block) Vulcano::Rule.new(id, &block)
execute_rule(r)
# existing = Vulcano::Rule.registry[id]
# if existing.nil?
#
# else
# p "RULE #{id} was found: #{existing}"
# # TODO: alter existing rule
# end
end end
def require_rules id, &block def require_rules id, &block
files = get_spec_files_for_profile id files = ::Vulcano::DSL.get_spec_files_for_profile id
end end
def include_rules id, &block def include_rules id, &block
files = get_spec_files_for_profile id files = ::Vulcano::DSL.get_spec_files_for_profile id
# files.each do |file| # files.each do |file|
# eval(File::read(file), file, 1) # eval(File::read(file), file, 1)
# end # end
end end
private # Register a given rule with RSpec and
# let it run. This happens after everything
# Attach an ID attribute to the # else is merged in.
# metadata of all examples def self.execute_rule r
# TODO: remove this once IDs are in rspec-core
def set_rspec_ids(obj, id)
obj.examples.each {|ex|
ex.metadata[:id] = id
}
obj.children.each {|c|
set_rspec_ids(c, id)
}
end
def execute_rule r
checks = r.instance_variable_get(:@checks) checks = r.instance_variable_get(:@checks)
id = r.instance_variable_get(:@id) id = r.instance_variable_get(:@id)
checks.each do |m,a,b| checks.each do |m,a,b|
@ -84,7 +56,21 @@ module Vulcano::DSL
end end
end end
def get_spec_files_for_profile id private
# Attach an ID attribute to the
# metadata of all examples
# TODO: remove this once IDs are in rspec-core
def self.set_rspec_ids(obj, id)
obj.examples.each {|ex|
ex.metadata[:id] = id
}
obj.children.each {|c|
self.set_rspec_ids(c, id)
}
end
def self.get_spec_files_for_profile id
base_path = '/etc/vulcanosec/tests' base_path = '/etc/vulcanosec/tests'
path = File.join( base_path, id ) path = File.join( base_path, id )
# find all files to be included # find all files to be included
@ -102,10 +88,18 @@ module Vulcano::DSL
end end
module Vulcano::GlobalDSL
def rule id, &block
r = Vulcano::Rule.new(id, &block)
::Vulcano::DSL.execute_rule(r)
end
end
module Vulcano::DSLHelper module Vulcano::DSLHelper
def self.bind_dsl(scope) def self.bind_dsl(scope)
(class << scope; self; end).class_exec do (class << scope; self; end).class_exec do
include Vulcano::DSL include Vulcano::DSL
include Vulcano::GlobalDSL
end end
end end
end end