Module: Thor::Base::ClassMethods
- Defined in:
- lib/thor/rich_options/base.rb
Instance Method Summary collapse
-
#class_at_least_one(*args, &block) ⇒ Object
Adds and declareds option group for required at least one of options in the block and arguments.
-
#class_at_least_one_option_names ⇒ Object
Returns this class at least one of required options array set, looking up in the ancestors chain.
-
#class_exclusive(*args, &block) ⇒ Object
Adds and declareds option group for exclusive options in the block and arguments.
-
#class_exclusive_option_names ⇒ Object
Returns this class exclusive options array set, looking up in the ancestors chain.
Instance Method Details
#class_at_least_one(*args, &block) ⇒ Object
Adds and declareds option group for required at least one of options in the block and arguments. You can declare options as the outside of the block.
Examples
class_at_least_one do
class_option :one
class_option :two
end
Or
class_option :one
class_option :two
class_at_least_one :one, :two
If you do not give “–one” and “–two”. AtLeastOneRequiredArgumentError will be raised. You can use class_at_least_one and class_exclusive at the same time.
class_exclusive do
class_at_least_one do
class_option :one
class_option :two
end
end
Then it is required either only one of “–one” or “–two”.
158 159 160 161 |
# File 'lib/thor/rich_options/base.rb', line 158 def class_at_least_one(*args, &block) (:class_options, :class_at_least_one_option_names, *args, &block) end |
#class_at_least_one_option_names ⇒ Object
Returns this class at least one of required options array set, looking up in the ancestors chain.
Rturns
Array[Array]
97 98 99 |
# File 'lib/thor/rich_options/base.rb', line 97 def class_at_least_one_option_names @class_at_least_one_option_names ||= from_superclass(:class_at_least_one_option_names, []) end |
#class_exclusive(*args, &block) ⇒ Object
Adds and declareds option group for exclusive options in the block and arguments. You can declare options as the outside of the block.
Parameters
Examples
class_exclusive do
class_option :one
class_option :two
end
Or
class_option :one
class_option :two
class_exclusive :one, :two
If you give “–one” and “–two” at the same time. ExclusiveArgumentsError will be raised.
124 125 126 127 |
# File 'lib/thor/rich_options/base.rb', line 124 def class_exclusive(*args, &block) (:class_options, :class_exclusive_option_names, *args, &block) end |
#class_exclusive_option_names ⇒ Object
Returns this class exclusive options array set, looking up in the ancestors chain.
Rturns
Array[Array]
88 89 90 |
# File 'lib/thor/rich_options/base.rb', line 88 def class_exclusive_option_names @class_exclusive_option_names ||= from_superclass(:class_exclusive_option_names, []) end |