Class: OptparsePlus::OptPlus
- Inherits:
-
Object
- Object
- OptparsePlus::OptPlus
- Defined in:
- lib/optparse_plus.rb
Constant Summary collapse
- RUBY_OPTIONS =
YAML.load()
- RUBY_OPTION_TO_LABEL =
{ "E" => :optplus_ruby_encoding, "d" => :optplus_ruby_debug, }
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_source ⇒ Object
readonly
Returns the value of attribute config_source.
-
#opt ⇒ Object
writeonly
Sets the attribute opt.
Class Method Summary collapse
Instance Method Summary collapse
- #config_to_args(label, config = @config) ⇒ Object
- #inherit_ruby_options(*short_option_names) ⇒ Object
-
#initialize(config_yaml_source) ⇒ OptPlus
constructor
A new instance of OptPlus.
- #opt_on ⇒ Object
- #reflect_callback(label) ⇒ Object
Constructor Details
#initialize(config_yaml_source) ⇒ OptPlus
Returns a new instance of OptPlus.
65 66 67 68 69 70 71 |
# File 'lib/optparse_plus.rb', line 65 def initialize(config_yaml_source) @config_source = config_yaml_source @config = YAML.load(config_yaml_source) @ruby_option_callbacks = ruby_option_callbacks @callbacks = {} @opt = nil end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
32 33 34 |
# File 'lib/optparse_plus.rb', line 32 def callbacks @callbacks end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/optparse_plus.rb', line 32 def config @config end |
#config_source ⇒ Object (readonly)
Returns the value of attribute config_source.
32 33 34 |
# File 'lib/optparse_plus.rb', line 32 def config_source @config_source end |
#opt=(value) ⇒ Object (writeonly)
Sets the attribute opt
33 34 35 |
# File 'lib/optparse_plus.rb', line 33 def opt=(value) @opt = value end |
Class Method Details
.create_opt(config_yaml_source) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/optparse_plus.rb', line 52 def self.create_opt(config_yaml_source) opt_plus = OptPlus.new(config_yaml_source) if = opt_plus.config["banner"] opt = ::OptionParser.new() else opt = ::OptionParser.new end opt.setup_opt_plus(opt_plus) opt end |
Instance Method Details
#config_to_args(label, config = @config) ⇒ Object
83 84 85 86 87 |
# File 'lib/optparse_plus.rb', line 83 def config_to_args(label, config=@config) = config[label.to_s] %w(short long desc description).map {|type| [type] } .select {|option| not option.nil? }.flatten end |
#inherit_ruby_options(*short_option_names) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/optparse_plus.rb', line 89 def (*short_option_names) short_option_names.each do |opt_name| label = RUBY_OPTION_TO_LABEL[opt_name] args = config_to_args(label, RUBY_OPTIONS) callback = @ruby_option_callbacks[label] @opt.on(*args, callback) end end |
#opt_on ⇒ Object
73 74 75 |
# File 'lib/optparse_plus.rb', line 73 def opt_on @callbacks.keys.each {|label| reflect_callback(label) } end |
#reflect_callback(label) ⇒ Object
77 78 79 80 81 |
# File 'lib/optparse_plus.rb', line 77 def reflect_callback(label) callback = @callbacks[label] args = config_to_args(label) @opt.on(*args, callback) end |