Let’s me sum some stuff up first before I start :
- Gem : A Gem is a “library”, a pack of code, in the programmatic language we call Ruby, that enables us to use functions not built in the languages without having to rewrite the code. When one feels he has enough code to share, he can wrap it up in a “Gem” that will be easily installable and usable by the other Ruby programmers.
- Faker : Faker is a gem that basically gives you random data. Let’s say you want to make a huge database and want to test the load for when you have more than 1000 users. Instead of writing either 1000 times the same name or use 1000 names you write one by one, Faker will generate a random one for each of these entries. Pretty useful.
But then, Faker generates what it has been built for. Generating team names, or even slogans, are not what it has been made for. So as a 2 days project with my fellow boots of Phase 1 DevBootcamp we created one that made the things we want. You can check the code here : Github, and more info on how to download the gem on : Rubygem.
Basically, we used bundle to make the gem architecture, the files we needed. Then, we took a look at how Faker was built and decided to go around that same way, with our data stocked in a yaml file, and using the yaml module to load it and get the data we wanted in ruby.
And we end up with a gem that has 4 different functions :
1
|
|
generates a random Character name from a famous movie, or tv show. The titles include The Lord of the Ring, Superman, Starwars, friends, or futurama.
1
|
|
generates a random name from the movie or tv show that you called. Your options are :
- friends
- entourage
- sex_and_the_city
- batman
- startrek
- superman
- star_wars
- the_lord_of_the_rings
- napolean_dynamite
- snow_white
- back_to_the_future
- the_wizard_of_oz
- toy_story
- the_simpsons
- futurama
- monty_python
1
|
|
generates a random slogan from a 587 quotes database
1
|
|
generates a team name from a list of adjectives and a list of animal names. Expect some funny names, gender-confused pandas is a good one ;)
With all that, we ended up making the gem with a simple
1
|
|
And then send it to rubygems.org, and here we go.
All in all, we ended up shipping a gem without knowing about gem building/shipping, building dozens of tests without knowing about rspec… a good 2 days of intense learning, a lot of fun, and we end up with an usable tool. I’m pretty happy about it!