A RubyGem, commonly called just a gem, is a packaged Ruby library, which installation allows you use the functionality of a common library in your application. This tutorial is meant to explain how to create and deploy a RubyGem.
0. Prerequisites
Make sure the following prerequisites are met:
1. Creating a New Gem App
Creating a new gem can be done by going toFile | New Project...and choosingRuby Gem. Specify location and name of the project, then choose Ruby SDK supposed to be used for the project and setCreate bin folderandCreate test folderif these folders are required to be generated for the project:
The skeleton of the application is automatically generated:
2. Configuring Git Root
Unregistered Git root notification appears as soon as the application structure is ready:
PressConfigureor go toSettings -> Version Controland add application root to version control if required:
3. Adding Working Code
Navigate to the main module (⌘O/Ctrl+N) and add the code expected to be doing something:
Then navigate to Gemspec file (⌘⇧O/Ctrl+Shift+N) and set up the summary and description sections:
4. Building Gem
Go to theTools | Gemmenu and selectBuild Gemoption. After the gem is built a file with the gem extension can be found in the project view:
5. Installing Gem Locally
Before being uploaded to RubyGems repository the gem needs to be tested, so lets install the gem. Go toRun | Edit Configurations...and add a newGem Commandas described:
Apply the changes and run the configuration (⌃R/Shift+F10), wait for the gem being installed:
6. Smoke Testing with IRB
To test the gem run IRB console (Tools | Run IRB Console...) and call the methods of the newly installed gem:
7. Gem Publishing
Gem can now be pushed withTools | Gem -> Push Gemoption:
If you want to use your own gem repository, please change your .gemspec file according to RubyGems guides: