Class: Ame::Options::Undefined
- Inherits:
-
Object
- Object
- Ame::Options::Undefined
- Defined in:
- lib/ame-1.0/options/undefined.rb
Overview
The options to a method in its undefined state.
Instance Method Summary collapse
-
#define ⇒ Options
The defined version of the receiver.
-
#flag(short, long, default, description) {|?| ... } ⇒ self
Adds a new Flag to the receiver.
-
#include?(name) ⇒ Boolean
True if the receiver has any kind of option named NAME.
-
#initialize ⇒ Undefined
constructor
A new instance of Undefined.
-
#multioption(short, long, argument, type, description) {|?| ... } ⇒ self
Adds a new Multioption to the receiver.
-
#option(short, long, argument, default, description) {|?| ... } ⇒ self
Adds a new Ame::Option to the receiver.
-
#options_must_precede_arguments ⇒ self
Forces options to the method about to be defined to precede any arguments, lest they be seen as arguments.
-
#switch(short, long, argument, default, argument_default, description) {|?| ... } ⇒ self
Adds a new Switch to the receiver.
-
#toggle(short, long, default, description) {|?| ... } ⇒ self
Adds a new Flag to the receiver.
Constructor Details
#initialize ⇒ Undefined
Returns a new instance of Undefined.
6 7 8 9 10 |
# File 'lib/ame-1.0/options/undefined.rb', line 6 def initialize @options = {} @ordered = [] @options_must_precede_arguments = ENV.include? 'POSIXLY_CORRECT' end |
Instance Method Details
#define ⇒ Options
Returns The defined version of the receiver.
90 91 92 |
# File 'lib/ame-1.0/options/undefined.rb', line 90 def define Ame::Options.new(@options, @ordered, @options_must_precede_arguments) end |
#flag(short, long, default, description) {|?| ... } ⇒ self
Adds a new Flag to the receiver.
28 29 30 |
# File 'lib/ame-1.0/options/undefined.rb', line 28 def flag(short, long, default, description, &validate) self << Ame::Flag.new(short, long, default, description, &validate) end |
#include?(name) ⇒ Boolean
Returns True if the receiver has any kind of option named NAME.
85 86 87 |
# File 'lib/ame-1.0/options/undefined.rb', line 85 def include?(name) @options.include? name end |
#multioption(short, long, argument, type, description) {|?| ... } ⇒ self
Adds a new Multioption to the receiver.
79 80 81 |
# File 'lib/ame-1.0/options/undefined.rb', line 79 def multioption(short, long, argument, type, description, &validate) self << Ame::Multioption.new(short, long, argument, type, description, &validate) end |
#option(short, long, argument, default, description) {|?| ... } ⇒ self
Adds a new Ame::Option to the receiver.
68 69 70 |
# File 'lib/ame-1.0/options/undefined.rb', line 68 def option(short, long, argument, default, description, &validate) self << Ame::Option.new(short, long, argument, default, description, &validate) end |
#options_must_precede_arguments ⇒ self
Forces options to the method about to be defined to precede any arguments, lest they be seen as arguments. If not given, the behaviour will depend on whether ‘ENV` has been set or not.
16 17 18 19 |
# File 'lib/ame-1.0/options/undefined.rb', line 16 def @options_must_precede_arguments = true self end |
#switch(short, long, argument, default, argument_default, description) {|?| ... } ⇒ self
Adds a new Switch to the receiver.
57 58 59 |
# File 'lib/ame-1.0/options/undefined.rb', line 57 def switch(short, long, argument, default, argument_default, description, &validate) self << Ame::Switch.new(short, long, argument, default, argument_default, description, &validate) end |
#toggle(short, long, default, description) {|?| ... } ⇒ self
Adds a new Flag to the receiver. Also adds a --no-LONG flag that’s the inverse of this flag.
41 42 43 44 45 46 47 48 |
# File 'lib/ame-1.0/options/undefined.rb', line 41 def toggle(short, long, default, description, &validate) flag = Ame::Flag.new(short, long, default, description, &validate) raise ArgumentError, 'long can’t be empty' if flag.long.empty? self << flag add(Ame::Flag.new('', 'no-%s' % flag.long, nil, description){ |, argument| [flag.name] = validate ? validate.call(, !argument) : !argument }) end |