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.



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

def initialize(argv)
  @argv = argv

  @options = {}

  parse!
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

#connection_optionsObject (readonly)

Returns the value of attribute connection_options.



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

def connection_options
  @connection_options
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#parse!Object



34
35
36
37
38
39
40
41
42
# File 'lib/raq/runner.rb', line 34

def parse!
  parser.parse! @argv
  # Defaults < Configuration File < Command line arguments

  @options = symbolized_configuration_file_data(@options.delete(:config)).merge(@options)

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

#parserObject



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

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

    opts.on("-C", "--config CONFIG.YML", "YAML file containing Raq configuration") { |path| @options[:config] = path }
  end
end