Class: Thor::Task
- Inherits:
-
Struct
- Object
- Struct
- Thor::Task
- Defined in:
- lib/thor/task.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#meth ⇒ Object
Returns the value of attribute meth.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#usage ⇒ Object
Returns the value of attribute usage.
Class Method Summary collapse
Instance Method Summary collapse
- #formatted_usage(namespace = false) ⇒ Object
- #namespace(remove_default = true) ⇒ Object
- #parse(obj, args) ⇒ Object
- #run(obj, *params) ⇒ Object
- #with_klass(klass) ⇒ Object
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description
5 6 7 |
# File 'lib/thor/task.rb', line 5 def description @description end |
#klass ⇒ Object
Returns the value of attribute klass
5 6 7 |
# File 'lib/thor/task.rb', line 5 def klass @klass end |
#meth ⇒ Object
Returns the value of attribute meth
5 6 7 |
# File 'lib/thor/task.rb', line 5 def meth @meth end |
#opts ⇒ Object
Returns the value of attribute opts
5 6 7 |
# File 'lib/thor/task.rb', line 5 def opts @opts end |
#usage ⇒ Object
Returns the value of attribute usage
5 6 7 |
# File 'lib/thor/task.rb', line 5 def usage @usage end |
Class Method Details
.dynamic(meth, klass) ⇒ Object
6 7 8 |
# File 'lib/thor/task.rb', line 6 def self.dynamic(meth, klass) new(meth, "A dynamically-generated task", meth.to_s, nil, klass) end |
Instance Method Details
#formatted_usage(namespace = false) ⇒ Object
54 55 56 57 |
# File 'lib/thor/task.rb', line 54 def formatted_usage(namespace = false) (namespace ? self.namespace + ':' : '') + usage + (opts ? " " + opts.formatted_usage : "") end |
#namespace(remove_default = true) ⇒ Object
39 40 41 |
# File 'lib/thor/task.rb', line 39 def namespace(remove_default = true) Thor::Util.constant_to_thor_path(klass, remove_default) end |
#parse(obj, args) ⇒ Object
10 11 12 13 14 |
# File 'lib/thor/task.rb', line 10 def parse(obj, args) list, hash = parse_args(args) obj. = hash run(obj, *list) end |
#run(obj, *params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/thor/task.rb', line 16 def run(obj, *params) raise NoMethodError, "the `#{meth}' task of #{obj.class} is private" if (obj.private_methods + obj.protected_methods).include?(meth) obj.send(meth, *params) rescue ArgumentError => e # backtrace sans anything in this file backtrace = e.backtrace.reject {|frame| frame =~ /^#{Regexp.escape(__FILE__)}/} # and sans anything that got us here backtrace -= caller raise e unless backtrace.empty? # okay, they really did call it wrong raise Error, "`#{meth}' was called incorrectly. Call as `#{formatted_usage}'" rescue NoMethodError => e begin raise e unless e. =~ /^undefined method `#{meth}' for #{Regexp.escape(obj.inspect)}$/ rescue raise e end raise Error, "The #{namespace false} namespace doesn't have a `#{meth}' task" end |
#with_klass(klass) ⇒ Object
43 44 45 46 47 |
# File 'lib/thor/task.rb', line 43 def with_klass(klass) new = self.dup new.klass = klass new end |