lib/qed/demo.rb in qed-2.6.3 vs lib/qed/demo.rb in qed-2.7.0
- old
+ new
@@ -5,72 +5,74 @@
require 'qed/core_ext'
require 'qed/parser'
require 'qed/evaluator'
require 'qed/applique'
- # The Demo class ecapsulates a demonstration document.
+ # The Demo class ecapsulates a demonstrandum script.
#
class Demo
# Demonstrandum file.
attr :file
# Parser mode.
attr :mode
- # Working directory.
- attr :cwd
-
- # Scope to run demonstration within. (Known as a "World" in Cucumber.)
- attr :scope
-
- # New Script
+ # Steup new Demo instance.
+ #
+ # @param [String] file
+ # Path to demo file.
+ #
+ # @param [Hash] options
+ #
+ # @option options [Symbol] :mode
+ # Either `:comment` or other for normal mode.
+ #
+ # @option options [Strng] :at
+ # Working directory.
+ #
+ # @option options [Array] :applique
+ # Overriding applique. Used to import demos into other demos safely.
+ #
+ # @option options [Scope] :scope
+ # Overriding scope, otherwise new Scope instance is created.
+ #
def initialize(file, options={})
- @file = file
- @mode = options[:mode]
- @cwd = options[:at] || fallback_cwd
+ @file = file
- @scope = options[:scope] || Scope.new(applique, cwd, file)
-
- @binding = @scope.__binding__
- #apply_environment
+ @mode = options[:mode]
+ @applique = options[:applique]
end
- # One binding per demo.
- def binding
- @binding #||= @scope.__binding__
- end
-
# Expanded dirname of +file+.
def directory
@directory ||= File.expand_path(File.dirname(file))
end
# File basename less extension.
def name
@name ||= File.basename(file).chomp(File.extname(file))
end
- #
- def evaluate(code, line)
- #eval(code, @binding, @file, line)
- @scope.eval(code, @file, 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)
+ Dir[location + '/**/*'].each do |file|
+ list << Applique.for(file)
end
end
list
)
end
+ #
+ def applique_prime
+ applique.first
+ end
+
# Returns a list of applique directories to be used by this
# demonstrastion.
def applique_locations
@applique_locations ||= (
locations = []
@@ -92,24 +94,23 @@
@steps ||= parser.parse
end
# Parse and cache demonstration script.
#
- # @return [Array] abstract syntax tree
+ # @return [Array] list of steps (abstract syntax tree)
alias_method :parse, :steps
# Get a new Parser instance for this demo.
#
# @return [Parser] parser for this demo
def parser
- Parser.new(file, :mode=>mode)
+ Parser.new(self, :mode=>mode)
end
- #
- def run(*observers)
- evaluator = Evaluator.new(self, *observers)
- evaluator.run
+ # Run demo through {Evaluator} instance with given observers.
+ def run(options={})
+ Evaluator.run(self, options)
end
#
#def source
# @source ||= (
@@ -120,14 +121,9 @@
# #else
# File.read(file)
# #end
# )
#end
-
- # This shouldn't be needed, but is here as a precaution.
- def fallback_cwd
- @dir ||= File.join(Dir.tmpdir, 'qed', File.filename(Dir.pwd), Time.new.strftime("%Y%m%d%H%M%S"))
- end
end
end