This method is only available on newer versions.
The first available version (v2_6_3) is shown here.
invoke_from_option(*names, &block)
public
Invoke a thor class based on the value supplied by the user to the given
option named “name”. A class option must be created before this method
is invoked for each name given.
Examples
class GemGenerator<Bundler::Thor::Groupclass_option:test_framework,:type=>:stringinvoke_from_option:test_frameworkend
In some cases, you want to invoke a thor class if
some option is true or false. This is automatically handled by invoke_from_option.
Then the option name is used to invoke the generator.
Preparing for invocation
In some cases you want to customize how a specified hook is going to be
invoked. You can do that by overwriting the class method
prepare_for_invocation. The class method must necessarily return a klass
and an optional command.
You can also supply a block to customize how the option is going to be
invoked. The block receives two parameters, an instance of the current
class and the klass to be invoked.
# File lib/bundler/vendor/thor/lib/thor/group.rb, line 110
def invoke_from_option(*names, &block)
options = names.last.is_a?(Hash) ? names.pop : {}
verbose = options.fetch(:verbose, :white)
names.each do |name|
unless class_options.key?(name)
raise ArgumentError, "You have to define the option #{name.inspect} " "before setting invoke_from_option."
end
invocations[name] = true
invocation_blocks[name] = block if block_given?
class_eval def _invoke_from_option_#{name.to_s.gsub(/\W/, '_')} return unless options[#{name.inspect}] value = options[#{name.inspect}] value = #{name.inspect} if TrueClass === value klass, command = self.class.prepare_for_invocation(#{name.inspect}, value) if klass say_status :invoke, value, #{verbose.inspect} block = self.class.invocation_blocks[#{name.inspect}] _invoke_for_class_method klass, command, &block else say_status :error, %(\#{value} [not found]), :red end end, __FILE__, __LINE__
end
end