Ruby Gems or “gem” is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries. It is easy to manage and install to your system and it can be used by various rails applications.
Every RoR developer might have customised a gem at least once in his career, but not each one of them has actually, created a gem. Here, I am going to give a basic idea about how to create a new gem and how to publish it.
Calcio d'inizio
Prima di iniziare assicurati di utilizzare l'ultima versione di Ruby. RVM è davvero utile in questo caso;
How to name your Gem?
Don’t blindly give a random name to your gem. Please take care of the following;
Every il trattino rappresenta una struttura (folder, module) immersion
Every il carattere di sottolineatura rappresenta un'unione nel nome della classe
Some examples:
gem new_test_gem
- richiedono 'new_test_gem'
- modulo/classe NewTestGem
And:
gem gem-structure-new_test_gem
- richiedono 'gem/structure/new_test_gem
- modulo/classe Gem::Struttura::NewTestGem
How to create your Gem?
Per creare una gemma;
Gemma in bundle $ new_test_gem
Creerà alcuni file e directory di base.
Where to add your code or job
Your beautiful code goes here
#lib/new_test_gem.rb
Una volta aggiunto il codice nel file lib, dovrai aggiornare il file gemspec;
# new_test_gem.gemspec
What is Gem Versioning?
# lib/new_test_gem/version.rb
module NewTestGem
VERSION = “0.1.0”
FINE
A couple of things about what you create
- Una versione gemma è una stringa di 3 numeri: "XYZ".
- Incremento X, Y, Z
incrementing Z, a small change and it’s called the ‘build’ number(e.g. changing label/text) and no change in any functionality.
incrementing Y, a new functionality change and it’s called the ‘minor’ number. But no compatibility issues with the previously released versions.
incrementing X, severe change and it’s called the ‘major’ number and the change no longer compatible with the previous versions.
The gem below (Gem-release) helps you to version your gem with a simple ‘bump’ command.
Gemma di rilascio della gemma:
https://github.com/svenfuchs/gem-release
How to build your Gem?
Una volta ottenuto il nostro gemspec, dobbiamo costruire una gemma da esso. Possiamo, quindi, installarlo localmente per testarlo.
Installazione e test
Once your gem is built, you will have to install it to your system.
And of course, you have to test it properly.
Installazione gemma $ ./new_test_gem-0.1.0.gem
How to push your Gem?
Per farlo, dovremo creare un account su RubyGems.org.
Then, it will be available to the other rubyists all over the world through rubygems.org.
This is done by;
La gemma $ spinge new_test_gem-0.0.1.gem
Per verificarlo, la tua gemma viene aggiunta a RubyGems.org
$ elenco gemme -r new_test_gem
Fine
That’s all it takes to create a gem!
If you want to create a Ruby Gem, you can further read through the following write-ups;
http://guides.rubygems.org/make-your-own-gem/
http://railscasts.com/episodes/135-making-a-gem
https://gorails.com/episodes/creating-gems-for-frontend-javascript-libraries