Class: Raq::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/raq/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
# File 'lib/raq/runner.rb', line 9

def initialize(argv)
  @argv = argv

  @options = {}

  parse!
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/raq/runner.rb', line 6

def command
  @command
end

#connection_optionsObject (readonly)

Returns the value of attribute connection_options.



7
8
9
# File 'lib/raq/runner.rb', line 7

def connection_options
  @connection_options
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/raq/runner.rb', line 5

def options
  @options
end

Instance Method Details

#parse!Object



31
32
33
34
35
# File 'lib/raq/runner.rb', line 31

def parse!
  parser.parse! @argv
  @command = @argv.shift
  @connection_options = @options.reject {|k,v| [:queue, :type].include?(k) }
end

#parserObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/raq/runner.rb', line 17

def parser
  @parser ||= OptionParser.new do |opts|
    opts.on("-H", "--host HOST", "AMQP HOST address (default: #{@options[:host]}") { |host| @options[:host] = host }
    opts.on("-p", "--port PORT", "AMQP PORT") { |port| @options[:port] = port.to_i }
    opts.on("-q", "--queue QUEUE","AMQP Queue to use") { |queue| @options[:queue] = queue }
    opts.on("-u", "--user USER","AMQP User to connect as") { |user| @options[:user] = user }

    opts.on("-t", "--type TYPE","AMQP message type") { |type| @options[:type] = type }

    opts.on("-r", "--require LIBRARY","Require the provided library before starting") { |lib| require lib }
    # ... and on
  end
end