class Tryouts
def self.parse_file(fpath)
Parse a +_tryouts.rb+ file. See Tryouts::CLI::Run for an example.
def self.parse_file(fpath) raise "No such file: #{fpath}" unless File.exists?(fpath) file_content = File.read(fpath) to = Tryouts.new begin to.paths << fpath to.instance_eval file_content, fpath # After parsing the DSL, we'll know the group name. # If a Tryouts object already exists for that group # we'll use that instead and re-parse the DSL. if @@instances.has_key? to.group to = @@instances[to.group] to.instance_eval file_content, fpath end rescue SyntaxError, LoadError, Exception, TypeError, RuntimeError, NoMethodError, NameError => ex to.errors << ex Tryouts.failed = true # It's helpful to display the group name file_content.match(/^group (.+?)$/) do |x,t| # We use eval as a quick cheat so we don't have # to parse all the various kinds of quotes. to.group = eval x.captures.first end end @@instances[to.group] = to to end