Sha256: 90f68650fc010ec78ade16f7fa2b804aa885ba1c9f6439c54964e8fb7e669423

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

# coding: utf-8
# TODO: Separate Gem?

class Siege
  DEFAULTS = {
    duration:   '30s',
    users:      15,
    delay:      1,
    rc:         File.expand_path('../siege/data/siegerc', __FILE__)
  }
  OPTIONS = {
    benchmark:  '-b',
    duration:   '-t',
    file:       '-f',
    header:     '-H',
    internet:   '-i',
    quiet:      '-q',
    user_agent: '-A',
    users:      '-c',
    rc:         '-R',
    delay:      '-d',
    verbose:    '-v'
  }

  attr_reader :conf, :results

  def initialize(urls, conf)
    @url_file = TempFile.with_content urls
    @conf     = DEFAULTS.merge conf
    @results  = Results.for executor
  end

  def executor
    puts "Sieging with:\n\tsiege #{cli_opts} -f #{@url_file.name} 2>&1"
    `siege #{cli_opts} -f #{@url_file.name} 2>&1`
  end

  def cli_opts
    @conf.flat_map { |opt, val| [OPTIONS[opt], val] }.
        join(' ').
        gsub(/(\-\w) true/, '\1').
        gsub(/\-\w false/, '')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bombard-0.0.3 lib/siege.rb