Class: Terminate::Options
- Inherits:
-
Object
- Object
- Terminate::Options
- Defined in:
- lib/terminate/options.rb
Instance Attribute Summary collapse
-
#help ⇒ Object
readonly
Returns the value of attribute help.
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #pid ⇒ Object
- #signal ⇒ Object
- #timeout ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/terminate/options.rb', line 5 def initialize @help = '' @options = {} OptionParser.new do |opts| opts. = "Usage: wait_stop [pid] [options]" opts.on('-t', '--timeout=TIMEOUT', 'Timeout to kill(seconds, default is 10)') { |v| @options[:timeout] = v } opts.on('-s', '--signal=SIGNAL', 'SIGNAL to terminate(default TERM)') { |v| @options[:signal] = v } @help = opts.to_s end.parse! end |
Instance Attribute Details
#help ⇒ Object (readonly)
Returns the value of attribute help.
3 4 5 |
# File 'lib/terminate/options.rb', line 3 def help @help end |
Instance Method Details
#pid ⇒ Object
16 17 18 |
# File 'lib/terminate/options.rb', line 16 def pid ARGV[0].to_i end |
#signal ⇒ Object
25 26 27 |
# File 'lib/terminate/options.rb', line 25 def signal @options[:signal] || 'TERM' end |
#timeout ⇒ Object
20 21 22 23 |
# File 'lib/terminate/options.rb', line 20 def timeout timeout = @options[:timeout].to_i timeout <= 0 ? 10 : timeout end |