CLI Gem part two: scope and flow!

That made so much sense.

So, looking carefully at which methods called which, I started mapping them out with used draw.

io, and ended up with this:Each box contains a method or input.

I decided to color them by class, so I could more easily intuit which methods were causing problems.

The green ones are from my CLI class; the orange ones are from my Scraper class and the yellow ones are from my Mission class.

The chart took a few hours to make because as I built it and saw the connections between the methods, I’d notice areas for improvement and make changes accordingly.

By the time I finished the chart, my flow was still broken, but I could easily see why: I was using the same method, #display_missions, to give the user the results of a new search and a refined search.

It’s a best practice to write code in an abstract way so it can be re-used.

But my method was not entirely abstract.

In addition to displaying search results ( that part *was* abstract), it included specific instructions for next steps for the user: namely, pick a mission number or refine your search.

I wanted to give users both options for new searches only, and just the pick-a-number option for refined searches.

The chart quickly showed me what days of testing could not make plain: all first-time searches results started with the method that’s now called #new_search on the chart (it used to be called #list_missions).

All refined searches started with #search_results.

All I had to do was remove the user prompts from the #display_missions method.

Then I used the newly-named #new_search method to call #display_missions, and then offer the options of picking a mission from that list, or doing a refined search.

Finally, I used the #select_missions method to call #display_missions and then offer only the option of picking a mission number.

After I did that, I tested again and … my CLI flow was finally fixed!I still have a project with more features than are necessary.

Luckily, if that’s a bad thing, I can easily use Github to revert back to the version that existed before I started adding features.


. More details

Leave a Reply