Class: Ralphttp::Starter

Inherits:
Object
  • Object
show all
Defined in:
lib/ralphttp/starter.rb

Overview

Loading class

Constant Summary collapse

PROTOCOLS =
%w(http https)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/ralphttp/starter.rb', line 6

def params
  @params
end

Instance Method Details

#argumentsObject

Public - Parse arguments for the script

Returns Hash of arguments



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ralphttp/starter.rb', line 26

def arguments
  options = {}

  begin
    params = OptionParser.new do |opts|
      opts.banner = 'Usage: ralphttp [OPTIONS]'

      opts.on('-c', '--concurrent NUM',
              'Number of concurrent connections')do |concurrent|
        options[:concurrent] = concurrent
      end

      opts.on('-n', '--requests NUM',
              'Total number of requests to use') do |reqs|
        options[:requests] = reqs
      end

      opts.on('-u', '--url URL', 'URL of the page to benchmark') do |url|
        options[:url] = url
      end

      opts.on('-a', '--user-agent STRING', 'User Agent to use') do |ua|
        options[:useragent] = ua
      end

      opts.on('-d', '--detail', 'Show detailed report') do |d|
        options[:detail] = d
      end

      opts.on('-s', '--csv FILE', 'Output CSV data into file') do |c|
        options[:csv] = c
      end

      opts.on('-h', '--help', 'Show help') do
        puts opts
        exit
      end
    end
    params.parse!
    options[:url] = url_parse(options[:url]) unless options[:url].nil?
    @params = params
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
   puts params
   exit
  end # End begin

  options
end

#startObject

Public - Initialize the start with new



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ralphttp/starter.rb', line 9

def start
  options = arguments

  if options[:url].nil? || options[:concurrent].nil? ||
    options[:requests].nil?
    puts @params
    exit
  end

  wreckit = Ralphttp::Wreckit.new(options)
  wreckit.blast
  wreckit.analyze
end