-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hi, all, @codereading/readers.
I'm reading thor, and here's my report and questions.
Given a task like this.
class Example < Thor
desc "show example", "show example by how it works"
def show
puts "this is how it works"
end
end
Here's how thor works.
-
when *class Example < Thor *, thor will register Example into namespaces.
using:def inherited(klass)
this method will be called, every time a subclass is inheriting Thor.
-
when * desc "", "", method_options*, thor will call class methods desc, method_options.
using:def desc; ... ; end def method_options; ... ; end
it will save desc, and options to instance variables, @desc, @method_options.
-
when ** def show **. thor will save show into array tasks[].
using:def method_added(meth)
it creates a task, and save current @desc, @method_options to the task,
then add this new task into array tasks[] -
when you call "thor example:show", thor will look for namespaces and task names.
def find_class_and_task_by_namespace()
once it find 1 namespace aka class, and 1 match task name inside that namespace.
it create a instance, and instance.send(task_name, *args).
thanks
Jarodzzzzz
hope it helps some one who just started reading.