Class: MQBench::Options
- Inherits:
-
Object
- Object
- MQBench::Options
- Defined in:
- lib/mqbench/options.rb
Constant Summary collapse
- MANDATORY_OPTS =
[:mode, :size, :count]
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #is_valid? ⇒ Boolean
- #show_usage ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mqbench/options.rb', line 9 def initialize(argv) @opt = OptionParser.new @conf = {} @opt.on("-m m", "--mode m", "[mandatory] broker type {amqp|stomp|kafka}") {|v| @conf[:mode] = v} @opt.on("-s s", "--size s", "[mandatory] message size (bytes)") {|v| @conf[:size] = v.to_i} @opt.on("-c c", "--count c", "[mandatory] message counts") {|v| @conf[:count] = v.to_i} @opt.on("-u u", "--user p", "specify user-id to login broker") {|v| @conf[:user] = v} @opt.on("-w w", "--pass w", "specify password to login broker") {|v| @conf[:pass] = v} @opt.on("-h h", "--host h", "specify host where broker is running") {|v| @conf[:host] = v} @opt.on("-p p", "--port p", "specify TCP port-number which broker listens") {|v| @conf[:port] = v.to_i} begin @opt.parse!(argv) rescue OptionParser::MissingArgument => e puts @opt.help exit 1 end end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
7 8 9 |
# File 'lib/mqbench/options.rb', line 7 def conf @conf end |
Instance Method Details
#is_valid? ⇒ Boolean
29 30 31 |
# File 'lib/mqbench/options.rb', line 29 def is_valid? not MANDATORY_OPTS.map {|x| @conf.key? x}.include?(false) end |
#show_usage ⇒ Object
33 34 35 |
# File 'lib/mqbench/options.rb', line 33 def show_usage puts @opt.help end |