Parent

Included Modules

Thor::Group

Thor has a special class called Thor::Group. The main difference to Thor class is that it invokes all tasks at once. It also include some methods that allows invocations to be done at the class method, which are not available to Thor tasks.

Public Class Methods

desc(description=nil) click to toggle source

The descrition for this Thor::Group. If none is provided, but a source root exists, tries to find the USAGE one folder above it, otherwise searches in the superclass.

Parameters

description:The description for this Thor::Group.
    # File lib/thor/group.rb, line 15
15:     def desc(description=nil)
16:       case description
17:         when nil
18:           @desc ||= from_superclass(:desc, nil)
19:         else
20:           @desc = description
21:       end
22:     end
help(shell, options={}) click to toggle source

Prints help information.

Options

short:When true, shows only usage.
    # File lib/thor/group.rb, line 44
44:     def help(shell, options={})
45:       if options[:short]
46:         shell.say banner
47:       else
48:         shell.say "Usage:"
49:         shell.say "  #{banner}"
50:         shell.say
51:         class_options_help(shell)
52:         shell.say self.desc if self.desc
53:       end
54:     end
invoke(*names, &block) click to toggle source

Invoke the given namespace or class given. It adds an instance method that will invoke the klass and task. You can give a block to configure how it will be invoked.

The namespace/class given will have its options showed on the help usage. Check invoke_from_option for more information.

    # File lib/thor/group.rb, line 75
75:     def invoke(*names, &block)
76:       options = names.last.is_a?(Hash) ? names.pop : {}
77:       verbose = options.fetch(:verbose, :white)
78: 
79:       names.each do |name|
80:         invocations[name] = false
81:         invocation_blocks[name] = block if block_given?
82: 
83:         class_eval "def _invoke_\#{name.to_s.gsub(/\\W/, '_')}\nklass, task = self.class.prepare_for_invocation(nil, \#{name.inspect})\n\nif klass\nsay_status :invoke, \#{name.inspect}, \#{verbose.inspect}\nblock = self.class.invocation_blocks[\#{name.inspect}]\n_invoke_for_class_method klass, task, &block\nelse\nsay_status :error, %(\#{name.inspect} [not found]), :red\nend\nend\n", __FILE__, __LINE__
84:       end
85:     end
invoke_from_option(*names, &block) click to toggle source

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 < Thor::Group
    class_option :test_framework, :type => :string
    invoke_from_option :test_framework
  end

Boolean options

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 task.

Custom invocations

You can also supply a block to customize how the option is giong to be invoked. The block receives two parameters, an instance of the current class and the klass to be invoked.

     # File lib/thor/group.rb, line 130
130:     def invoke_from_option(*names, &block)
131:       options = names.last.is_a?(Hash) ? names.pop : {}
132:       verbose = options.fetch(:verbose, :white)
133: 
134:       names.each do |name|
135:         unless class_options.key?(name)
136:           raise ArgumentError, "You have to define the option #{name.inspect} " << 
137:                                "before setting invoke_from_option."
138:         end
139: 
140:         invocations[name] = true
141:         invocation_blocks[name] = block if block_given?
142: 
143:         class_eval "def _invoke_from_option_\#{name.to_s.gsub(/\\W/, '_')}\nreturn unless options[\#{name.inspect}]\n\nvalue = options[\#{name.inspect}]\nvalue = \#{name.inspect} if TrueClass === value\nklass, task = self.class.prepare_for_invocation(\#{name.inspect}, value)\n\nif klass\nsay_status :invoke, value, \#{verbose.inspect}\nblock = self.class.invocation_blocks[\#{name.inspect}]\n_invoke_for_class_method klass, task, &block\nelse\nsay_status :error, %(\\\#{value} [not found]), :red\nend\nend\n", __FILE__, __LINE__
144:       end
145:     end
remove_invocation(*names) click to toggle source

Remove a previously added invocation.

Examples

  remove_invocation :test_framework
     # File lib/thor/group.rb, line 170
170:     def remove_invocation(*names)
171:       names.each do |name|
172:         remove_task(name)
173:         remove_class_option(name)
174:         invocations.delete(name)
175:         invocation_blocks.delete(name)
176:       end
177:     end
start(given_args=ARGV, config={}) click to toggle source

Start works differently in Thor::Group, it simply invokes all tasks inside the class.

    # File lib/thor/group.rb, line 27
27:     def start(given_args=ARGV, config={})
28:       super do
29:         if Thor::HELP_MAPPINGS.include?(given_args.first)
30:           help(config[:shell])
31:           return
32:         end
33: 
34:         args, opts = Thor::Options.split(given_args)
35:         new(args, opts, config).invoke
36:       end
37:     end

Protected Class Methods

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.