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.
79 80 81 82 83 84 85 |
# File 'lib/optparse_plus.rb', line 79 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.
46 47 48 |
# File 'lib/optparse_plus.rb', line 46 def callbacks @callbacks end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
46 47 48 |
# File 'lib/optparse_plus.rb', line 46 def config @config end |
#config_source ⇒ Object (readonly)
Returns the value of attribute config_source.
46 47 48 |
# File 'lib/optparse_plus.rb', line 46 def config_source @config_source end |
#opt=(value) ⇒ Object (writeonly)
Sets the attribute opt
47 48 49 |
# File 'lib/optparse_plus.rb', line 47 def opt=(value) @opt = value end |
Class Method Details
.create_opt(config_yaml_source) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/optparse_plus.rb', line 66 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
97 98 99 100 101 |
# File 'lib/optparse_plus.rb', line 97 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
103 104 105 106 107 108 109 110 |
# File 'lib/optparse_plus.rb', line 103 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
87 88 89 |
# File 'lib/optparse_plus.rb', line 87 def opt_on @callbacks.keys.each {|label| reflect_callback(label) } end |
#reflect_callback(label) ⇒ Object
91 92 93 94 95 |
# File 'lib/optparse_plus.rb', line 91 def reflect_callback(label) callback = @callbacks[label] args = config_to_args(label) @opt.on(*args, callback) end |