Nowadays all the functionalities in Rails are built as Ruby gems. For example we can use devise gem for the authentication part of the application. It’s like a package or library that is written in Ruby programming language. Moreover it can be imported and used by others in their programs.
Schritt 1
Bundler is like a dependency management tool for Ruby, which is also used by Rails. We will use Bundler for the basic gem structure. It helps us to install the correct versions of the gem and forces us to use the same in the application. So the command for that is, gem bundler install
After bundling, we should specify the gem “name” that we are going to create i.e. Bundle gem “testgem” will create a repository shown below
So in this we can see the basic gem structure. Under the lib folder, version file will be used to mention the version of the Gem. We can edit the version as per our convenience and release it that will be the version in Rubygems.
Schritt 2
We will consider testgem.gemspec, with testgem as the name of the gem that we will create for sample. It will be used to set up the gem on rubgems, for e.g., name of the gem, summary, description, files that are required in this project, test files that are used to testing the files in the project etc.
Rake file: – This makes releasing the new versions of the gem, and also helps other developers to check the test cases if they are going to modify the particular gem.
After the rake, we should create a test folder and test cases for each segments will be included here in the app directory.
Schritt 3
Planning to make a rubygem, then we need to analyse the requirements what to build up and what all functionalities should be included in that.
While generating, we should create a sample.rb file inside lib folder and create own class with namespace because the other plugin has also the same classes then it will get conflict in the names. And require the sample.rb file in the testgem.rb file like reqiure “testgem/sample”.
Step 4
We have require “bundler/gem_tasks” in rake file so when we run rake release, it will release the gem to ruby gems and make it available. Push to git repository
RubyGems are commonly used in Applications
1) Rails – Rails is a ruby gem
2) Better Errors / Rails Footnotes – Debugging tools for Rails/Rack apps.
3) Resque / Delayed Job / Sidekiq – Used for creating background jobs, placing them on multiple queues, and processing them later.
4) Cancan / Devise – Authorization / Authentication Gems for Ruby on Rails.
5) Letter Opener – Test your emails within the browser itself.
6) Discourse – Discussion Forum.
7) Carrierwave / Paperclip – Classy solutions for file uploads for Rails.
8) Whenever – Cron jobs (scheduled tasks) in Ruby.
9) Thin / Unicorn / Puma – Web servers.
RailsCarma provide end to end Ruby on Rails Development services including, consulting, architecture, building, management and extension to companies around the globe. You can also hire Ruby on Rails-Entwickler mit einem einfachen Einstellungsprozess. Kontaktieren Sie uns, um mehr zu erfahren.