Common Anti-Patterns in CLI Data Gem
Last updated
Last updated
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
67 lines (52 sloc) 2.48 KB
This video walks through the process of refactoring a CLI Gem fixing common anti-patterns in CLI Gem applications
Define anti-patterns
Pinpoint flaws in Gem
Zipper Pattern
Format user output
Decouple scraping functionality
Create Instances of our Model/Class
[MP4](Find learn s3 source?)
what do we mean by anti-patterns
explain our gem functionality
explain our classes
find flaws in gem
bunch of different arrays of data instead of unified objects
explain zipper pattern
too many calls to website
We never instantiate instances of our class
a ton of scraping methods in our story object
hard coded maximum number for user input
using each
instead of collect
examine app in pry
fix formatting for output
build functionality to scrape individual story
make it work using our zipper pattern
fix undefined method error
output scraped story
move scraping logic to a Scraper class
change class methods to instance methods
define responsibility of Scraper class
scrape individual li tags of stories
grab individual attributes of that story with css selectors.
use those individual story details info to create a new story instance
add functionalty to Story class to keep track of all its instances
test scraper functionality
last article causes an error
use rescue
to pinpoint source of error
create logic to prevent the error stemming from different tags in final article
implement our new functionality throughout the app
use our new logic to obtain and output the stories in cli class
add functionality to scrape individual article
realize how efficient our app is now that we've utilized Object Orientation
a story object now has power and convenient methods
commit and examine github diff post refactor
<iframe width="100%" height="720" src="" frameborder="0" allowfullscreen></iframe>
View on Learn.co and start learning to code for free.