Class: RubybenchRunner::RailsRunner

Inherits:
BaseRunner show all
Defined in:
lib/rubybench_runner/rails_runner.rb

Constant Summary

Constants inherited from BaseRunner

BaseRunner::COPY_FOLDERS, BaseRunner::DEFAULT_OPTS, BaseRunner::HELPERS_VERSION_FILE

Instance Attribute Summary

Attributes inherited from BaseRunner

#opts, #repo_path, #script_url

Instance Method Summary collapse

Methods inherited from BaseRunner

#bundle_install, #check_dependencies, #copy_helpers, #create_tmpdir, #dest_dir, #download_script, #initialize, #print_results, #process_results, #run, #run_benchmarks, #script_full_path, #script_name, #script_path, #setup_db, #write_gemfile

Constructor Details

This class inherits a constructor from RubybenchRunner::BaseRunner

Instance Method Details

#benchmark_nameObject



25
26
27
# File 'lib/rubybench_runner/rails_runner.rb', line 25

def benchmark_name
  @benchmark_name ||= "Rails"
end

#commandObject



3
4
5
6
7
8
9
# File 'lib/rubybench_runner/rails_runner.rb', line 3

def command
  command = "RAILS_ENV=production #{super}"
  if require_db?
    command = "DATABASE_URL=#{database_url} #{command}"
  end
  command
end

#database_urlObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubybench_runner/rails_runner.rb', line 11

def database_url
  return @db_url if @db_url
  raw_config = RubybenchRunner::Configurations.new
  config = OpenStruct.new(raw_config[opts.db.to_sym])
  url = "#{opts.db}://#{config.user}"
  url += ":#{config.password}" if config.password
  url += "@#{config.host}" if config.host
  url += ":#{config.port}" if config.port
  url += "/#{config.dbname}"
  with_prep_statement = opts.wps == true
  url += "?prepared_statements=#{with_prep_statement}"
  @db_url = url
end

#gemfile_contentObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubybench_runner/rails_runner.rb', line 29

def gemfile_content
  @gemfile_content ||= <<~GEMFILE
    source 'https://rubygems.org'

    gem 'rails', path: '#{@repo_path}'

    gem 'mysql2', '0.5.2'
    gem 'pg', '1.1.4'
    gem 'benchmark-ips', '~> 2.7.2'
    gem 'redis', '~> 4.1.2'
    gem 'puma', '~> 3.12.1'
  GEMFILE
end

#require_db?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
# File 'lib/rubybench_runner/rails_runner.rb', line 47

def require_db?
  filename = @script_url.split("/")[-1]
  res = filename.match?(/activerecord|scaffold/)
  if res && !opts.db
    puts "This benchmark requires database to run. Please specify the `--db` option (see --help for details)"
    exit 1
  end
  res
end

#save_dirObject



43
44
45
# File 'lib/rubybench_runner/rails_runner.rb', line 43

def save_dir
  @save_dir ||= File.join(dest_dir, "rails")
end