Building the clone
Finally we get to the meat of the chapter. Here we roll up our sleeves and get to the business of coding Tinyclone. The overall web application is around 200 lines of code, so we will put everything into a single file called tinyclone.rb
. With a bit of Sinatra magic this becomes our entire web application.
We will be looking at Tinyclone from two simple perspectives. The first is the data model. The data model is an abstract view of the objects that are used to represent the application problem space. The second is the application flow, which describes how the application uses the data model to provide the functions needed. As the application isn't very large, we can inspect its code in detail, something we will not be able to do in later chapters when we deal with larger applications.
Data model
Let's look at the data model first. The model we use has three classes. The Link
is the main class for the application, one that has an identifier (short URL) that represents an...