Class: QED::Session
Overview
The Session class encapsulates a set of demonstrations and the procedure for looping through them and running each in turn.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Demonstration files.
-
#format ⇒ Object
Output format.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#trace ⇒ Object
Trace mode.
Instance Method Summary collapse
-
#demos ⇒ Object
Returns an Array of Demo instances.
-
#initialize(files, options = {}) ⇒ Session
constructor
New Session.
- #observers ⇒ Object
-
#reporter ⇒ Object
Instance of selected Reporter subclass.
-
#require_reporters ⇒ Object
TODO: Ultimately use Plugin library to support custom reporters?.
-
#run ⇒ Object
Run session.
Constructor Details
#initialize(files, options = {}) ⇒ Session
New Session
25 26 27 28 29 30 31 32 33 |
# File 'lib/qed/session.rb', line 25 def initialize(files, ={}) require_reporters @files = [files].flatten @mode = [:mode] @trace = [:trace] || false @format = [:format] || :dotprogress end |
Instance Attribute Details
#files ⇒ Object (readonly)
Demonstration files.
13 14 15 |
# File 'lib/qed/session.rb', line 13 def files @files end |
#format ⇒ Object
Output format.
16 17 18 |
# File 'lib/qed/session.rb', line 16 def format @format end |
#mode ⇒ Object
Returns the value of attribute mode.
22 23 24 |
# File 'lib/qed/session.rb', line 22 def mode @mode end |
Instance Method Details
#demos ⇒ Object
Returns an Array of Demo instances.
56 57 58 |
# File 'lib/qed/session.rb', line 56 def demos @demos ||= files.map{ |file| Demo.new(file, :mode=>mode) } end |
#observers ⇒ Object
61 62 63 |
# File 'lib/qed/session.rb', line 61 def observers [reporter] end |
#reporter ⇒ Object
Instance of selected Reporter subclass.
48 49 50 51 52 53 |
# File 'lib/qed/session.rb', line 48 def reporter @reporter ||= ( name = Reporter.constants.find{ |c| /#{format}/ =~ c.downcase } Reporter.const_get(name).new(:trace => trace) ) end |
#require_reporters ⇒ Object
TODO: Ultimately use Plugin library to support custom reporters?
41 42 43 44 45 |
# File 'lib/qed/session.rb', line 41 def require_reporters Dir[File.dirname(__FILE__) + '/reporter/*'].each do |file| require file end end |
#run ⇒ Object
Run session.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/qed/session.rb', line 66 def run #profile.before_session(self) reporter.before_session(self) demos.each do |demo| demo.run(*observers) #pid = fork { demo.run(*observers) } #Process.detach(pid) end reporter.after_session(self) #profile.after_session(self) end |