Parent

Class Index [+]

Quicksearch

Thor::Task

Constants

FILE_REGEXP

Public Class Methods

new(name, description, long_description, usage, options=nil) click to toggle source
   # File lib/bundler/vendor/thor/task.rb, line 5
5:     def initialize(name, description, long_description, usage, options=nil)
6:       super(name.to_s, description, long_description, usage, options || {})
7:     end

Public Instance Methods

formatted_usage(klass, namespace = true, subcommand = false) click to toggle source

Returns the formatted usage by injecting given required arguments and required options into the given usage.

    # File lib/bundler/vendor/thor/task.rb, line 33
33:     def formatted_usage(klass, namespace = true, subcommand = false)
34:       if namespace
35:         namespace = klass.namespace
36:         formatted = "#{namespace.gsub(/^(default)/,'')}:"
37:         formatted.sub!(/.$/, ' ') if subcommand
38:       end
39: 
40:       formatted ||= ""
41: 
42:       # Add usage with required arguments
43:       formatted << if klass && !klass.arguments.empty?
44:         usage.to_s.gsub(/^#{name}/) do |match|
45:           match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
46:         end
47:       else
48:         usage.to_s
49:       end
50: 
51:       # Add required options
52:       formatted << " #{required_options}"
53: 
54:       # Strip and go!
55:       formatted.strip
56:     end
hidden?() click to toggle source
    # File lib/bundler/vendor/thor/task.rb, line 14
14:     def hidden?
15:       false
16:     end
run(instance, args=[]) click to toggle source

By default, a task invokes a method in the thor class. You can change this implementation to create custom tasks.

    # File lib/bundler/vendor/thor/task.rb, line 20
20:     def run(instance, args=[])
21:       public_method?(instance) ?
22:         instance.send(name, *args) : instance.class.handle_no_task_error(name)
23:     rescue ArgumentError => e
24:       handle_argument_error?(instance, e, caller) ?
25:         instance.class.handle_argument_error(self, e) : (raise e)
26:     rescue NoMethodError => e
27:       handle_no_method_error?(instance, e, caller) ?
28:         instance.class.handle_no_task_error(name) : (raise e)
29:     end

Protected Instance Methods

handle_argument_error?(instance, error, caller) click to toggle source
    # File lib/bundler/vendor/thor/task.rb, line 79
79:     def handle_argument_error?(instance, error, caller)
80:       not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
81:         saned = sans_backtrace(error.backtrace, caller)
82:         # Ruby 1.9 always include the called method in the backtrace
83:         saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
84:       end
85:     end
handle_no_method_error?(instance, error, caller) click to toggle source
    # File lib/bundler/vendor/thor/task.rb, line 87
87:     def handle_no_method_error?(instance, error, caller)
88:       not_debugging?(instance) &&
89:         error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
90:     end
not_debugging?(instance) click to toggle source
    # File lib/bundler/vendor/thor/task.rb, line 60
60:     def not_debugging?(instance)
61:       !(instance.class.respond_to?(:debugging) && instance.class.debugging)
62:     end
required_options() click to toggle source
    # File lib/bundler/vendor/thor/task.rb, line 64
64:     def required_options
65:       @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
66:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.