-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Walkthrough #4
Comments
will add more tomorrow. |
It looks like that's the rvm wrapper, not thor/bin/thor. Note the path. |
Well ive been busy working on a side project but going to try and plow through some more here. resuming where I left off: I actually missed something previously. in the bin/thor Thor::Runner.start is called If you go to lib/thor/runner.rb you will notice there is no start method, so where is it? Thor::Runner inherits from Thor like so
A bit mind bending but ill ignore asking why for the moment. So maybe the start method is in Thor's class definition in lib/thor.rb . No such luck. But after doing a project wide search for "start" I found it in thor/base.rb
I spent ages thinking how Runner get its hands on it. Then in thor.rb I noticed at line 378 it includes Thor::Base and Thor::Base has a hook for when it is included via line 81
So it extends the Thor class with Base.start. Thor is then inherited by Runner which now has a shiny start method. Ok with that over lets resume from this start method. |
Why did the authors create a Base moduleActually I wanted to know why did the authors created this Base module. Why didnt they just write those methods into the Thor class definition in lib/thor.rb. I believe the answer is because of the class Thor::Groups. I havent used thor groups before but you can learn more on the wiki about this functionality. The main difference is explained from code comments
The class Thor::Groups also requires some of the Base methods and includes Thor::Base just like the regular Thor class does. Runner gets lots of methods like startSo Runner, which inherits from Thor now has a number of class methods such as Lets look at Runners inherited start method
Ignoring the config[:shell] line for now, the next method This too is another class method that was originally in Base::ClassMethods but was extended into Thor and via inheritance available to Runner.
Extracting the task name from the arguments listSince
if we use pry to inspect what args (ARGV) looks like ala
we get This is set as the value for regarding
The second part of the OR expression is simply making sure no dashes are present in the args. Im not sure what the significance of this but its probably to do with -- flags or something. all_tasks and superclassesMoving on the next line in dispatch is all_tasks is another class method that is defined in Base::ClassMethods and eventually extended into Thor just like the start method above. This is being called in the context of Runner base.rb line 331
from_superclass, another inherited method, is defined further down in base.rb and looks like this
Ill save these for the next comment. |
@codereading/readers
(Eventually this will get edited and placed on the readme. )
In a directory of your choice create this file
2 Run
thor app:boom
You should get a stacktrace roughly similiar to this
The stacktrace is ordered with the last method called being first. i.e.
The top line is the last method called - the method with our raise call.
The bottom line is the birthpoint of the program.
Look for the first lines mentioning the thor codebase
These two lines are the first to do so
but on inspection of /bin/thor line 19 don't exist - Does anyone know why this happen???
anyway just skip them and move up the stacktrace untill you find something relevant. Luckily
show us the entry point. Not surprisingly it's the exec file at thor/bin/thor
this is run whenever you run
thor blahblahblah
on the command line.Thor::Runner.start is easy to find in your editor, just look at the stacktrace, it tells us it's at
from /Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby@codereading/gems/thor-0.16.0/lib/thor.rb:275:in 'dispatch'
from /Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby@codereading/gems/thor-0.16.0/ lib/thor/base.rb:425 :in 'start'
from /Users/adam/.rvm/gems/ruby-1.9.3-p194-Ruby@codereading/gems/thor-0.16.0/bin/thor:6:in '<top (required)>'
The text was updated successfully, but these errors were encountered: