I have been writing ruby gems for sometime now and always wish that there could be a command that can generate the gem structure/boilerplate and all the things I love pre-configured for me.
This is where Thor comes in handy. I am going to introduce you to Thor a.k.a the badass command line generator that will make your life easy when it comes to ruby gem creation.
I do want to mention Mariella Miranda who’s article on this topic inspired me to create a project which can be used as a gem generator to save you a lot of time.
just imagine this command:
Let’s do this!
Clone gem generator repository
Link to my repo https://github.com/saluminati/gem_generator
Your gem with all the required files is now created in the age_calculator directory
You can also append gem generator with use_rspec_suit and use_rubocop options to have rspec and rubocop pre-installed and configured with your gem
Once your gem is created, make sure that you try to build it.
Some explanation – As I promised
Content of gem_generator.thor file
Our main file is gem_generator.thor which holds everything together.
This file is extended from Thor::Group which, in a nutshell, execute all the methods defined in this class in the order they were defined.
If you look at the methods inside this class, they are creating the gem directory and copying the templates files within your gem namespace with everything per-configured.
Happy coding! please let me know if you run into any issue.