Step one of creating my Sinatra project was running Corneal to get my files in place and do my initial Github commit. I’m going to do my best to write this and subsequent posts in a way that would have been helpful for me when I was blindly googling for something that would help me understand things.
What is a Ruby Gem?
Ruby is the language we will use to create and manipulate the database that stores our data, as well as create and manipulate the routes that will be used with our website and what they will tell information to do.
A gem is a library, but it has a cute name because Ruby. For our purposes, a library is a collection of code that you can pull from to accomplish your tasks. Much like a library of books, it contains information that has already been gathered for you; it has code that was already written, to save you time and resources. When you are writing a research paper, you are not also going to write the history book you are pulling citations from; when you are working on a large project, you are not going to write all of the code from scratch. (You could, but … why?)
Corneal is a gem that was created to help us make Sinatra projects more easily in a way that is analogous to Rails, but is much lighter. Sinatra and Ruby on Rails are frameworks.
What are frameworks?
A framework is a type of library, and it means exactly that. If I were to give you a writing assignment, and tell you that it must include elements A, B, and C, in addition to other specifics, you might say I gave you a framework to operate within. I gave you a starting place that you can change and modify as you see fit. A software framework is a library of code that gives you a starting place; many pieces of code that you would otherwise create by hand are already built. It saves you from having to do the same tasks over and over and over.
Ruby on Rails (Rails) is a very popular framework that abstracts away much of the code needed to develop a web application. An abstraction in code is similar to an abstraction in art. Rather than a piece done in the photorealism style, you’re going to take away some of the details and move up a level or three. Take something like a face. A circle with three dots and a curve form a face, even though there is no detail that would tell you who it is. This is an abstraction. Rather than coding every single detail by hand, you can take away all but the most necessary parts, saving you time and mental space.
This is good for Future You, but Current You still needs to understand how things work and what they do. What seems like magic is never magic, it’s just something you don’t understand yet.
Sinatra is a much smaller framework than Rails in that it consists of much less code and it is lighter because it also does less for you. You are still responsible for the app structure and communication, versus Rails which has code that makes some assumptions that do look like magic.
We can use it to get used to utilizing the ideas we will need later: routes and how they work, connecting views to routes to models to migrations to the database, and where and when to implement logic.
So what does Corneal do?
So far we know that Corneal is a library, which means it has code already written for us, and it has to do with Sinatra and Rails.
Corneal was created to let us “build a Sinatra skeleton similar to running rails new APP-NAME.”
When you install Corneal (remember, it is a Ruby gem), you will be able to use one line in the terminal to generate the basic file structure you will need to make your application:
With this structure in place, we’re starting off much farther ahead than we would have if we had insisted on doing everything on our own. The wheel is good; we don’t need to reinvent it every single time we do a project.
How do we use Corneal here?
We are going to use Corneal to get the basic file structure in place and create our repository on Github. This is going to give us the outlines, and we will color them in later.