Class: Tomo::Runtime::Explanation

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/runtime/explanation.rb

Instance Method Summary collapse

Constructor Details

#initialize(applicable_hosts, plan, concurrency) ⇒ Explanation

Returns a new instance of Explanation.



6
7
8
9
10
# File 'lib/tomo/runtime/explanation.rb', line 6

def initialize(applicable_hosts, plan, concurrency)
  @applicable_hosts = applicable_hosts
  @plan = plan
  @concurrency = concurrency
end

Instance Method Details

#to_sObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tomo/runtime/explanation.rb', line 12

def to_s # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  desc = []
  threads = [applicable_hosts.length, concurrency].min
  desc << "CONCURRENTLY (#{threads} THREADS):" if threads > 1
  applicable_hosts.each do |host|
    indent = threads > 1 ? "  = " : ""
    desc << "#{indent}CONNECT #{host}"
  end
  plan.each do |steps|
    threads = [steps.length, concurrency].min
    desc << "CONCURRENTLY (#{threads} THREADS):" if threads > 1
    steps.each do |step|
      indent = threads > 1 ? "  = " : ""
      if threads > 1 && step.applicable_tasks.length > 1
        desc << "#{indent}IN SEQUENCE:"
        indent = indent.sub("=", "   ")
      end
      desc << step.explain.gsub(/^/, indent)
    end
  end
  desc.join("\n")
end