Class: Thor::Task
Direct Known Subclasses
Defined Under Namespace
Classes: Dynamic
Constant Summary collapse
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#usage ⇒ Object
Returns the value of attribute usage.
Instance Method Summary collapse
-
#formatted_usage(klass, namespace = true) ⇒ Object
Returns the formatted usage by injecting given required arguments and required options into the given usage.
-
#initialize(name, description, usage, options = nil) ⇒ Task
constructor
A new instance of Task.
-
#initialize_copy(other) ⇒ Object
:nodoc:.
-
#run(instance, args = []) ⇒ Object
By default, a task invokes a method in the thor class.
Methods inherited from Struct
Constructor Details
#initialize(name, description, usage, options = nil) ⇒ Task
Returns a new instance of Task.
20 21 22 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 20 def initialize(name, description, usage, =nil) super(name.to_s, description, usage, || {}) end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description
2 3 4 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 2 def description @description end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 2 def name @name end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 2 def @options end |
#usage ⇒ Object
Returns the value of attribute usage
2 3 4 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 2 def usage @usage end |
Instance Method Details
#formatted_usage(klass, namespace = true) ⇒ Object
Returns the formatted usage by injecting given required arguments and required options into the given usage.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 44 def formatted_usage(klass, namespace=true) namespace = klass.namespace unless namespace == false # Add namespace formatted = if namespace "#{namespace.gsub(/^(default|thor:runner:)/,'')}:" else "" end # Add usage with required arguments formatted << if klass && !klass.arguments.empty? usage.to_s.gsub(/^#{name}/) do |match| match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ') end else usage.to_s end # Add required options formatted << " #{}" # Strip and go! formatted.strip end |
#initialize_copy(other) ⇒ Object
:nodoc:
24 25 26 27 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 24 def initialize_copy(other) #:nodoc: super(other) self. = other..dup if other. end |
#run(instance, args = []) ⇒ Object
By default, a task invokes a method in the thor class. You can change this implementation to create custom tasks.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vendor/thor/lib/thor/task.rb', line 31 def run(instance, args=[]) public_method?(instance) ? instance.send(name, *args) : instance.class.handle_no_task_error(name) rescue ArgumentError => e handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e) : (raise e) rescue NoMethodError => e handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_task_error(name) : (raise e) end |