Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some Thor::Invocation refactoring.

  • Loading branch information...
commit 9b1a6119f82b1f1c64c79c95296c856e3febf438 1 parent 40d6950
@josevalim josevalim authored
View
2  Thorfile
@@ -3,7 +3,7 @@ require 'rubygems/specification'
require 'thor/tasks'
GEM = "thor"
-GEM_VERSION = "0.10.20"
+GEM_VERSION = "0.10.21"
AUTHOR = "Yehuda Katz"
EMAIL = "wycats@gmail.com"
HOMEPAGE = "http://yehudakatz.com"
View
22 lib/thor/invocation.rb
@@ -130,24 +130,30 @@ def _setup_for_invoke(name, sent_task=nil) #:nodoc:
when Symbol, String
name = name.to_s
- begin
- task = self.class.all_tasks[name]
- object, task = Thor::Util.namespace_to_thor_class(name) unless task
- task = task || sent_task
- rescue Thor::Error
- task = name
+ # If is not one of this class tasks, do a lookup.
+ unless task = self.class.all_tasks[name]
+ object, task = Thor::Util.namespace_to_thor_class(name, false)
+ task ||= sent_task
end
else
object, task = name, sent_task
end
- object ||= self
+ # If the object was not set, use self and use the name as task.
+ object, task = self, name unless object
+ return object, _validate_klass_and_task(object, task)
+ end
+
+ # Check if the object given is a Thor class object and get a task object
+ # for it.
+ #
+ def _validate_klass_and_task(object, task)
klass = object.is_a?(Class) ? object : object.class
raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base
task ||= klass.default_task if klass <= Thor
task = klass.all_tasks[task.to_s] || Task.dynamic(task) if task && !task.is_a?(Thor::Task)
- return object, task
+ task
end
end
View
6 lib/thor/util.rb
@@ -35,8 +35,6 @@ def self.find_by_namespace(namespace)
# older versions of Thor. On current versions, if you need to get the
# namespace from a class, just call namespace on it.
#
- # TODO Deprecate this method in the future.
- #
# ==== Parameters
# constant<Object>:: The constant to be converted to the thor path.
#
@@ -115,7 +113,7 @@ def self.snake_case(str)
# Thor::Error:: raised if the namespace evals to a class which does not
# inherit from Thor or Thor::Group.
#
- def self.namespace_to_thor_class(namespace)
+ def self.namespace_to_thor_class(namespace, raise_if_nil=true)
klass, task_name = Thor::Util.find_by_namespace(namespace), nil
if klass.nil? && namespace.include?(?:)
@@ -124,7 +122,7 @@ def self.namespace_to_thor_class(namespace)
klass = Thor::Util.find_by_namespace(namespace.join(":"))
end
- raise Error, "could not find Thor class or task '#{namespace}'" unless klass
+ raise Error, "could not find Thor class or task '#{namespace}'" if raise_if_nil && klass.nil?
return klass, task_name
end
View
4 thor.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{thor}
- s.version = "0.10.20"
+ s.version = "0.10.21"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Yehuda Katz"]
- s.date = %q{2009-06-29}
+ s.date = %q{2009-06-30}
s.description = %q{A gem that maps options to a class}
s.email = %q{wycats@gmail.com}
s.executables = ["thor", "rake2thor"]
Please sign in to comment.
Something went wrong with that request. Please try again.