Class: Raq::Runner
- Inherits:
-
Object
- Object
- Raq::Runner
- Defined in:
- lib/raq/runner.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#connection_options ⇒ Object
readonly
Returns the value of attribute connection_options.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #parse! ⇒ Object
- #parser ⇒ Object
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/raq/runner.rb', line 7 def command @command end |
#connection_options ⇒ Object (readonly)
Returns the value of attribute connection_options.
8 9 10 |
# File 'lib/raq/runner.rb', line 8 def @connection_options end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/raq/runner.rb', line 6 def @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 |
#parser ⇒ Object
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 |