Sha256: e879deb605e2ef8699d894cc21eb99094395b9a53b571494af7392016990f9b0

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

# coding: utf-8

module Bombard
  class Runner
    attr_reader :conf

    def initialize(opts)
      @global_opts = Config.for opts
      @conf        = @global_opts.bombard

      load_requirements
      publish
    end

    def results
      @results ||= Siege.new(build.urls, @global_opts.siege).results
    end

    def publisher
      @publisher ||= @conf.publisher ? class_for(@conf.publisher, Bombard::Publisher) : Bombard::Publisher::Console
    end

    def publish
      puts "Publishing using:\n\t#{publisher}"
      publisher.for(results).with_opts(@conf.publisher_opts).publish
    end

    def builder
      # TODO: Need a sane default or simply fail if not specified.
      @builder ||= @conf.builder ? class_for(@conf.builder, Bombard::Builder) : Bombard::Builder::Test
    end

    def build
      puts "Building using:\n\t#{builder}"
      builder.with_opts(@conf.builder_opts)
    end

    def load_requirements
      require_all @conf.require if @conf.require
    end

    private

    def class_for(child, parent = Object)
      child.split('::').reduce(parent) do |mod, class_name|
        mod.const_get(class_name)
      end
    rescue NameError
      abort "Can't find #{parent}::#{child}. You can load the contents of any directory using the --require switch."
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bombard-0.1.0 lib/bombard/runner.rb
bombard-0.0.6 lib/bombard/runner.rb
bombard-0.0.5 lib/bombard/runner.rb
bombard-0.0.4 lib/bombard/runner.rb
bombard-0.0.3 lib/bombard/runner.rb
bombard-0.0.2 lib/bombard/runner.rb