Class: Outliers::Run
- Inherits:
-
Object
- Object
- Outliers::Run
- Defined in:
- lib/outliers/run.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#results ⇒ Object
Returns the value of attribute results.
-
#thread_count ⇒ Object
Returns the value of attribute thread_count.
-
#threaded ⇒ Object
Returns the value of attribute threaded.
-
#threads ⇒ Object
Returns the value of attribute threads.
Instance Method Summary collapse
- #evaluate(name = nil, &block) ⇒ Object
- #failed ⇒ Object
-
#initialize(options = {}) ⇒ Run
constructor
A new instance of Run.
- #passed ⇒ Object
- #process_evaluations_in_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Run
Returns a new instance of Run.
5 6 7 8 9 10 11 |
# File 'lib/outliers/run.rb', line 5 def initialize(={}) @results = [] @threads = [] @threaded = false @thread_count = 1 Thread.abort_on_exception = true end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
3 4 5 |
# File 'lib/outliers/run.rb', line 3 def credentials @credentials end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/outliers/run.rb', line 3 def results @results end |
#thread_count ⇒ Object
Returns the value of attribute thread_count.
3 4 5 |
# File 'lib/outliers/run.rb', line 3 def thread_count @thread_count end |
#threaded ⇒ Object
Returns the value of attribute threaded.
3 4 5 |
# File 'lib/outliers/run.rb', line 3 def threaded @threaded end |
#threads ⇒ Object
Returns the value of attribute threads.
3 4 5 |
# File 'lib/outliers/run.rb', line 3 def threads @threads end |
Instance Method Details
#evaluate(name = nil, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/outliers/run.rb', line 24 def evaluate(name=nil, &block) while Thread.list.count > thread_count logger.info "Maximum concurrent threads running, sleeping." sleep 2 end evaluation = Proc.new { Evaluation.new(:name => name, :run => self).instance_eval &block } threaded ? threads << Thread.new { evaluation.call } : evaluation.call end |
#failed ⇒ Object
39 40 41 |
# File 'lib/outliers/run.rb', line 39 def failed @results.reject {|r| r.passed?} end |
#passed ⇒ Object
35 36 37 |
# File 'lib/outliers/run.rb', line 35 def passed @results.select {|r| r.passed?} end |
#process_evaluations_in_dir ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/outliers/run.rb', line 13 def process_evaluations_in_dir files.each do |file| next if File.directory? file next if File.extname(file) != '.rb' logger.info "Processing '#{file}'." self.instance_eval File.read(file) end threads.each {|t| t.join} end |