Class: DRbQS::Command::OptionSetting
- Inherits:
-
Object
- Object
- DRbQS::Command::OptionSetting
- Defined in:
- lib/drbqs/command_line/option_setting.rb
Instance Attribute Summary collapse
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
- #define(options = {}, &block) ⇒ Object
-
#initialize(help_message, setting) ⇒ OptionSetting
constructor
A new instance of OptionSetting.
- #parse!(argv) ⇒ Object
- #set(*args, &block) ⇒ Object
Constructor Details
#initialize(help_message, setting) ⇒ OptionSetting
Returns a new instance of OptionSetting.
6 7 8 9 |
# File 'lib/drbqs/command_line/option_setting.rb', line 6 def initialize(, setting) @opt_parser = OptionParser.new() @setting = setting end |
Instance Attribute Details
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
4 5 6 |
# File 'lib/drbqs/command_line/option_setting.rb', line 4 def setting @setting end |
Instance Method Details
#define(options = {}, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/drbqs/command_line/option_setting.rb', line 23 def define( = {}, &block) instance_eval(&block) if block_given? if [:log_level] set(:log_level, '--log-level LEVEL', String, "Set the log level. The value accepts 'fatal', 'error', 'warn', 'info', and 'debug'. The default is 'error'.") end if [:daemon] set(:daemon, '--daemon OUT', String, 'Execute as daemon and set output file for stdout and stderr.') end if [:debug] set(:debug, '--debug', 'Set $DEBUG true.') end end |
#parse!(argv) ⇒ Object
37 38 39 |
# File 'lib/drbqs/command_line/option_setting.rb', line 37 def parse!(argv) @opt_parser.parse!(argv) end |
#set(*args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/drbqs/command_line/option_setting.rb', line 11 def set(*args, &block) unless @setting raise "Not in method 'define'." end @opt_parser.on(*args[1..-1]) do |v| @setting.set(args[0], v) if block_given? yield(@opt_parser) end end end |