Class: Outliers::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/outliers/run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @results                  = []
  @threads                  = []
  @threaded                 = false
  @thread_count             = 1
  Thread.abort_on_exception = true
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



3
4
5
# File 'lib/outliers/run.rb', line 3

def credentials
  @credentials
end

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/outliers/run.rb', line 3

def results
  @results
end

#thread_countObject

Returns the value of attribute thread_count.



3
4
5
# File 'lib/outliers/run.rb', line 3

def thread_count
  @thread_count
end

#threadedObject

Returns the value of attribute threaded.



3
4
5
# File 'lib/outliers/run.rb', line 3

def threaded
  @threaded
end

#threadsObject

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

#failedObject



39
40
41
# File 'lib/outliers/run.rb', line 39

def failed
  @results.reject {|r| r.passed?}
end

#passedObject



35
36
37
# File 'lib/outliers/run.rb', line 35

def passed
  @results.select {|r| r.passed?}
end

#process_evaluations_in_dirObject



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