Class: Optimal::CI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/optimal/ci/runner.rb

Direct Known Subclasses

RSpec::Optimal::Runner

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
8
9
10
11
12
13
# File 'lib/optimal/ci/runner.rb', line 4

def initialize(args = [])
  @command_arguments_string = args.join(" ")
  @args = args

  if @args.empty?
    @paths = [dir]
  else
    @paths = @args
  end
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/optimal/ci/runner.rb', line 15

def run
  provider = Optimal::CI::Provider.detect

  if provider
    queue = Optimal::CI::Queue.new(provider, @command_arguments_string)
    queue.push(total_files)

    start_time = Time.now.to_i

    while files = queue.pop
      run_examples(files)
    end

    duration = Time.now.to_i - start_time

    queue.report_duration(duration)
    queue.report_http_calls

    Optimal::CI::Logger.info("reporting duration : #{duration}")
  else
    Optimal::CI::Logger.info("provider not found")
    system("#{command} #{@args.join(' ')}")
  end
end

#run_examples(examples) ⇒ Object



40
41
42
# File 'lib/optimal/ci/runner.rb', line 40

def run_examples(examples)
  raise "Not Implemented"
end

#total_filesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/optimal/ci/runner.rb', line 44

def total_files
  return @total_files if @total_files

  @total_files = []

  @paths.each do |path|
    if path.end_with?(files_end_with)
      @total_files << path
    else
      @total_files << Dir.glob("#{path.chomp("/")}/**/*#{files_end_with}")
    end
  end

  @total_files.flatten!

  @total_files
end