class Thor::Group
def invoke_from_option(*names, &block)
class and the klass to be invoked.
invoked. The block receives two parameters, an instance of the current
You can also supply a block to customize how the option is going to be
==== Custom invocations
and an optional command.
prepare_for_invocation. The class method must necessarily return a klass
invoked. You can do that by overwriting the class method
In some cases you want to customize how a specified hook is going to be
==== Preparing for invocation
option name is used to invoke the generator.
false. This is automatically handled by invoke_from_option. Then the
In some cases, you want to invoke a thor class if some option is true or
==== Boolean options
end
invoke_from_option :test_framework
class_option :test_framework, :type => :string
class GemGenerator < Thor::Group
==== Examples
method is invoked for each name given.
given option named "name". A class option must be created before this
Invoke a thor class based on the value supplied by the user to the
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 <<-METHOD, __FILE__, __LINE__ + 1 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 METHOD end end