Class: CommandKit::Options::OptionValue Private
- Inherits:
-
Arguments::ArgumentValue
- Object
- Arguments::ArgumentValue
- CommandKit::Options::OptionValue
- Defined in:
- lib/command_kit/options/option_value.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents an additional argument associated with an option flag.
Constant Summary collapse
- DEFAULT_USAGES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps OptionParser types to USAGE strings.
{ # NOTE: NilClass and Object are intentionally omitted Date => 'DATE', DateTime => 'DATE_TIME', Time => 'TIME', URI => 'URI', Shellwords => 'STR', String => 'STR', Integer => 'INT', Float => 'DEC', Numeric => 'NUM', OptionParser::DecimalInteger => 'INT', OptionParser::OctalInteger => 'OCT', OptionParser::DecimalNumeric => 'NUM|DEC', TrueClass => 'BOOL', FalseClass => 'BOOL', Array => 'LIST[,...]', Regexp => '/REGEXP/' }
Instance Attribute Summary collapse
-
#default ⇒ Object, ...
readonly
private
The default parsed value for the argument value.
-
#type ⇒ Class, ...
readonly
private
The desired type of the argument value.
Attributes inherited from Arguments::ArgumentValue
Class Method Summary collapse
-
.default_usage(type) ⇒ String?
private
Returns the default option value usage for the given type.
Instance Method Summary collapse
-
#default_value ⇒ Object
private
Returns a new default value.
-
#initialize(type: String, default: nil, usage: self.class.default_usage(type), **kwargs) ⇒ OptionValue
constructor
private
Initializes the option value.
-
#usage ⇒ String?
private
The usage string for the argument.
Methods inherited from Arguments::ArgumentValue
Constructor Details
#initialize(type: String, default: nil, usage: self.class.default_usage(type), **kwargs) ⇒ OptionValue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the option value.
70 71 72 73 74 75 76 77 78 |
# File 'lib/command_kit/options/option_value.rb', line 70 def initialize(type: String, default: nil, usage: self.class.default_usage(type), **kwargs) super(usage: usage, **kwargs) @type = type @default = default end |
Instance Attribute Details
#default ⇒ Object, ... (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default parsed value for the argument value.
50 51 52 |
# File 'lib/command_kit/options/option_value.rb', line 50 def default @default end |
#type ⇒ Class, ... (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The desired type of the argument value.
45 46 47 |
# File 'lib/command_kit/options/option_value.rb', line 45 def type @type end |
Class Method Details
.default_usage(type) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the default option value usage for the given type.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/command_kit/options/option_value.rb', line 92 def self.default_usage(type) DEFAULT_USAGES.fetch(type) do case type when Hash then type.keys.join('|') when Array then type.join('|') when Regexp then type.source when Class Inflector.underscore(Inflector.demodularize(type.name)).upcase else raise(TypeError,"unsupported option type: #{type.inspect}") end end end |
Instance Method Details
#default_value ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new default value.
122 123 124 125 126 |
# File 'lib/command_kit/options/option_value.rb', line 122 def default_value if @default.respond_to?(:call) then @default.call else @default.dup end end |
#usage ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The usage string for the argument.
111 112 113 114 115 |
# File 'lib/command_kit/options/option_value.rb', line 111 def usage string = @usage string = "[#{string}]" if optional? string end |