module ActiveScripts class Preparation # INFO: ActiveScripts::Preparation contains code that is # for retrieving and validating preparations. PREPARATIONS = Dir.entries("#{File.dirname(__FILE__)}/preparations") .drop(2) .reject { |f| ["base.rb"].include?(f) } .map { |f| File.basename(f, ".rb").to_sym } attr_accessor :preparation def initialize(preparation) @preparation = preparation end def self.find(preparation) new(preparation).find end def find assert_valid_preparation! return(@preparation) end private def assert_valid_preparation! unless PREPARATIONS.include?(@preparation) raise ArgumentError, "Unknown preparation: #{preparation.inspect}. Valid preparations are listed in the documentation." end end end end