module TemplateHelpers def load_recipe(recipe) return if exists?(recipe) eval_file_with_rescue "recipes/checks/#{recipe}.rb" eval_file_with_rescue "recipes/dependencies/#{recipe}.rb" eval_file_with_rescue "recipes/asks/#{recipe}.rb" eval_file "recipes/#{recipe}.rb" end def eval_file_with_rescue(source) eval_file(source) rescue StandardError end def eval_file(source) location = File.expand_path(find_in_source_paths(source)) unique_name = SecureRandom.hex define_singleton_method unique_name do instance_eval File.read(location) end public_send unique_name end def source_path(path) define_singleton_method :source_paths do [File.expand_path(File.dirname(path))] end end def erase_comments(file) gsub_file file, /^\s*#[^\n]*\n/, '' end end