Class: Benny::Executors::Environment
- Inherits:
-
Object
- Object
- Benny::Executors::Environment
- Defined in:
- lib/benny/executors/environment.rb
Instance Attribute Summary collapse
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(environments:, reporter:) ⇒ Environment
constructor
A new instance of Environment.
- #report(dir) ⇒ Object
- #run! ⇒ Object
- #run_one(environment, dir) ⇒ Object
Constructor Details
#initialize(environments:, reporter:) ⇒ Environment
Returns a new instance of Environment.
11 12 13 14 |
# File 'lib/benny/executors/environment.rb', line 11 def initialize(environments:, reporter:) @environments = environments @reporter = reporter end |
Instance Attribute Details
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
9 10 11 |
# File 'lib/benny/executors/environment.rb', line 9 def environments @environments end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
9 10 11 |
# File 'lib/benny/executors/environment.rb', line 9 def reporter @reporter end |
Class Method Details
.run!(*args) ⇒ Object
45 46 47 |
# File 'lib/benny/executors/environment.rb', line 45 def self.run!(*args) new(*args).run! end |
Instance Method Details
#report(dir) ⇒ Object
39 40 41 42 43 |
# File 'lib/benny/executors/environment.rb', line 39 def report(dir) Output.puts('Generating report...') metrics = Dir.glob(File.join(dir, '*.json')).map { |file| JSON.parse(File.read(file), symbolize_names: true) } reporter.report(metrics) end |
#run! ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/benny/executors/environment.rb', line 16 def run! Output.puts("Running benchmark for #{environments.size} environments. Reporter: #{reporter.class.name}") Dir.mktmpdir('benny') do |dir| environments.each do |e| run_one(e, dir) end report(dir) end end |
#run_one(environment, dir) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/benny/executors/environment.rb', line 27 def run_one(environment, dir) Bundler.with_original_env do ENV['BUNDLE_GEMFILE'] = environment.gemfile Output.puts('Installing dependencies...') Kernel.system(Shellwords.join(%w[bundle install])) Output.puts("Executing benchmark for '#{environment.name}'..") Kernel.system(Shellwords.join(['bundle', 'exec', 'benny', 'execute', '--result-path', dir, '--env-name', environment.name])) end end |