Class: QED::Demo
Overview
The Demo class ecapsulates a demonstration document.
Instance Attribute Summary collapse
-
#cwd ⇒ Object
readonly
Working directory.
-
#file ⇒ Object
readonly
Demonstrandum file.
-
#mode ⇒ Object
readonly
Parser mode.
-
#scope ⇒ Object
readonly
Scope to run demonstration within.
Instance Method Summary collapse
-
#applique ⇒ Object
Returns a cached Array of Applique modules.
-
#applique_locations ⇒ Object
Returns a list of applique directories to be used by this demonstrastion.
-
#binding ⇒ Object
One binding per demo.
-
#directory ⇒ Object
Expanded dirname of
file
. - #evaluate(code, line) ⇒ Object
-
#fallback_cwd ⇒ Object
This shouldn’t be needed, but is here as a precaution.
-
#initialize(file, options = {}) ⇒ Demo
constructor
New Script.
-
#name ⇒ Object
File basename less extension.
-
#parser ⇒ Parser
Get a new Parser instance for this demo.
- #run(*observers) ⇒ Object
-
#steps ⇒ Array
(also: #parse)
Demo steps, cached from parsing.
Constructor Details
#initialize(file, options = {}) ⇒ Demo
New Script
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/qed/demo.rb', line 27 def initialize(file, ={}) @file = file @mode = [:mode] @cwd = [:at] || fallback_cwd @scope = [:scope] || Scope.new(applique, cwd, file) @binding = @scope.__binding__ #apply_environment end |
Instance Attribute Details
#cwd ⇒ Object (readonly)
Working directory.
21 22 23 |
# File 'lib/qed/demo.rb', line 21 def cwd @cwd end |
#file ⇒ Object (readonly)
Demonstrandum file.
15 16 17 |
# File 'lib/qed/demo.rb', line 15 def file @file end |
#mode ⇒ Object (readonly)
Parser mode.
18 19 20 |
# File 'lib/qed/demo.rb', line 18 def mode @mode end |
#scope ⇒ Object (readonly)
Scope to run demonstration within. (Known as a “World” in Cucumber.)
24 25 26 |
# File 'lib/qed/demo.rb', line 24 def scope @scope end |
Instance Method Details
#applique ⇒ Object
Returns a cached Array of Applique modules.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/qed/demo.rb', line 60 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 |
#applique_locations ⇒ Object
Returns a list of applique directories to be used by this demonstrastion.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/qed/demo.rb', line 74 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 |
#binding ⇒ Object
One binding per demo.
39 40 41 |
# File 'lib/qed/demo.rb', line 39 def binding @binding #||= @scope.__binding__ end |
#directory ⇒ Object
Expanded dirname of file
.
44 45 46 |
# File 'lib/qed/demo.rb', line 44 def directory @directory ||= File.(File.dirname(file)) end |
#evaluate(code, line) ⇒ Object
54 55 56 57 |
# File 'lib/qed/demo.rb', line 54 def evaluate(code, line) #eval(code, @binding, @file, line) @scope.eval(code, @file, line) end |
#fallback_cwd ⇒ Object
This shouldn’t be needed, but is here as a precaution.
127 128 129 |
# File 'lib/qed/demo.rb', line 127 def fallback_cwd @dir ||= File.join(Dir.tmpdir, 'qed', File.filename(Dir.pwd), Time.new.strftime("%Y%m%d%H%M%S")) end |
#name ⇒ Object
File basename less extension.
49 50 51 |
# File 'lib/qed/demo.rb', line 49 def name @name ||= File.basename(file).chomp(File.extname(file)) end |
#parser ⇒ Parser
Get a new Parser instance for this demo.
103 104 105 |
# File 'lib/qed/demo.rb', line 103 def parser Parser.new(file, :mode=>mode) end |
#run(*observers) ⇒ Object
108 109 110 111 |
# File 'lib/qed/demo.rb', line 108 def run(*observers) evaluator = Evaluator.new(self, *observers) evaluator.run end |
#steps ⇒ Array Also known as: parse
Demo steps, cached from parsing.
91 92 93 |
# File 'lib/qed/demo.rb', line 91 def steps @steps ||= parser.parse end |