diff options
Diffstat (limited to 'lib/bundler/vendor/thor/task.rb')
-rw-r--r-- | lib/bundler/vendor/thor/task.rb | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/bundler/vendor/thor/task.rb b/lib/bundler/vendor/thor/task.rb index 6db3b608..02daa1a2 100644 --- a/lib/bundler/vendor/thor/task.rb +++ b/lib/bundler/vendor/thor/task.rb @@ -18,11 +18,21 @@ class Thor # By default, a task invokes a method in the thor class. You can change this # implementation to create custom tasks. def run(instance, args=[]) - public_method?(instance) ? - instance.send(name, *args) : instance.class.handle_no_task_error(name) + arity = nil + + if private_method?(instance) + instance.class.handle_no_task_error(name) + elsif public_method?(instance) + arity = instance.method(name).arity + instance.send(name, *args) + elsif local_method?(instance, :method_missing) + instance.send(:method_missing, name.to_sym, *args) + else + instance.class.handle_no_task_error(name) + end rescue ArgumentError => e handle_argument_error?(instance, e, caller) ? - instance.class.handle_argument_error(self, e) : (raise e) + instance.class.handle_argument_error(self, e, arity) : (raise e) rescue NoMethodError => e handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_task_error(name) : (raise e) @@ -34,8 +44,8 @@ class Thor if namespace namespace = klass.namespace formatted = "#{namespace.gsub(/^(default)/,'')}:" - formatted.sub!(/.$/, ' ') if subcommand end + formatted = "#{klass.namespace.split(':').last} " if subcommand formatted ||= "" @@ -70,8 +80,17 @@ class Thor !(instance.public_methods & [name.to_s, name.to_sym]).empty? end + def private_method?(instance) + !(instance.private_methods & [name.to_s, name.to_sym]).empty? + end + + def local_method?(instance, name) + methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false) + !(methods & [name.to_s, name.to_sym]).empty? + end + def sans_backtrace(backtrace, caller) #:nodoc: - saned = backtrace.reject { |frame| frame =~ FILE_REGEXP } + saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) } saned -= caller end |