lib/qed/demo.rb in qed-2.4.0 vs lib/qed/demo.rb in qed-2.5.0

- old
+ new

@@ -1,56 +1,41 @@ module QED + require 'yaml' - require 'facets/dir/ascend' - + require 'qed/core_ext' require 'qed/parser' require 'qed/evaluator' + require 'qed/applique' - # = Demo + # The Demo class ecapsulates a demonstration document. # class Demo - # - attr :applique - # Demonstrandum file. attr :file - # + # Parser mode. attr :mode - # + # Scope to run demonstration within. (Known as a "World" in Cucumber.) attr :scope # New Script - def initialize(file, applique, options={}) + def initialize(file, options={}) @file = file - @applique = applique.dup # localize copy of applique @scope = options[:scope] || Scope.new(applique, file) @mode = options[:mode] @binding = @scope.__binding__ - #@loadlist = [] #apply_environment end # One binding per script. def binding @binding #||= @scope.__binding__ end - # TODO: demo advice vs. applique advice - def advice - #@scope.__advice__ - @applique.__advice__ - end - - # - def advise(signal, *args) - advice.call(@scope, signal, *args) - end - # Expanded dirname of +file+. def directory @directory ||= File.expand_path(File.dirname(file)) end @@ -63,11 +48,53 @@ def evaluate(code, line) eval(code, @binding, @file, line) #@scope.module_eval(section.text, @file, section.line) end + # Returns a cached Array of Applique modules. + def applique + @applique ||= ( + list = [Applique.new] + applique_locations.each do |location| + Dir[location + '/**/*.rb'].each do |file| + list << Applique.new(file) + end + end + list + ) + end + + # Returns a list of applique directories to be used by this + # demonstrastion. + def applique_locations + @applique_locations ||= ( + locations = [] + Dir.ascend(File.dirname(file)) do |path| + break if path == Dir.pwd + dir = File.join(path, 'applique') + if File.directory?(dir) + locations << dir + end + end + locations + ) + end + + # Parse demonstration script. # + # Returns an abstract syntax tree. + def parse + Parser.new(file, :mode=>mode).parse + end + + # + def run(*observers) + evaluator = Evaluator.new(self, *observers) + evaluator.run + end + + # #def source # @source ||= ( # #case file # #when /^http/ # # ext = File.extname(file).sub('.','') @@ -75,21 +102,9 @@ # #else # File.read(file) # #end # ) #end - - # Parse script. - # Retruns an abstract syntax tree. - def parse - Parser.new(file, :mode=>mode).parse - end - - # - def run(*observers) - evaluator = Evaluator.new(self, *observers) - evaluator.run - end end end