CSC/ECE 517 Fall 2013/ch1 1w24 nv: Difference between revisions
No edit summary |
|||
(71 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Ruby Gem is a package manager for Ruby programming language. It allows users to easily download, install and use software packages on their system. The functionality of a Ruby application can be modified or extended with the help of Gems. In the version 1.9 of Ruby, Ruby Gems has been made a part of the standard library. This article would take the user on a tour of what ruby gems are all about and introduce the reader to various Ruby gems one can use to extend a Ruby application. Links for more details on Ruby gems are provided for the reader's benefit at the end of the article. | |||
== '''A Tour of Ruby Gems''' == | == '''A Tour of Ruby Gems''' == | ||
=== Definition of a Ruby Gem<ref>http://guides.rubygems.org/rubygems-basics/#installing_gems Ruby Gems guide</ref>=== | |||
In simple terms, a Ruby Gem is a package containing files that can be installed in a system and can help expand the functionality of a Ruby application. Ruby gems are very powerful. Ruby programmers create and publish Ruby Gems as open source in [https://github.com/ github]. It is very easy to install, upgrade and delete Gems in a system. | |||
=== Structure of Ruby Gem === | |||
Every Gem has a set of files and the following standard structure | |||
<pre> | |||
$ tree -d newgem | |||
|-- lib/ | |||
| |-- newgem.rb | |||
| `-- newgem/ | |||
| |-- base.rb | |||
| `-- version.rb | |||
|-- test/ | |||
|-- bin/ | |||
|-- Rakefile | |||
`-- newgem.gemspec</pre> | |||
---- | ---- | ||
The ''lib'' folder has the code of the ruby gem. It has ''newgem.rb'' file and a folder named ''newgem''. This folder has two files which are ''base.rb'' and ''version.rb''. The version number is recorded in ''version.rb'' and can be changed when the gem is updated. The ''bin'' directory has any binaries that is a part of the gem file and should be distributed with the gem. A gem usually has a [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile]. The rake program uses this to generate code and automate tests in addition to performing other tasks. The Gem specification file ''newgem.gemspec'' contains details specific to the gem. The file has details such as the gem name,the files that are in it, the gems it depends on for performing testing, the gems it depends on for actually running and other details. | |||
=== Listing existing Gems === | |||
To list the existing gems in a system ''list'' keyword can be used in the command line. | |||
<pre> | |||
$ gem list | |||
*** LOCAL GEMS *** | |||
actionmailer (3.2.3) | |||
actionpack (3.2.3) | |||
activemodel (3.2.3) | |||
activerecord (3.2.3) | |||
activeresource (3.2.3) | |||
activesupport (3.2.3) | |||
arel (3.0.2) | |||
bigdecimal (1.1.0) | |||
builder (3.0.4) | |||
bundler (1.3.5) | |||
capybara (2.1.0) | |||
coffee-rails (3.2.2) | |||
coffee-script (2.2.0) | |||
coffee-script-source (1.6.3) | |||
erubis (2.7.0) | |||
execjs (2.0.1) | |||
hike (1.2.3) | |||
i18n (0.6.5) | |||
io-console (0.3) | |||
journey (1.0.4) | |||
jquery-rails (3.0.4) | |||
</pre> | |||
=== Installing a new Gem === | |||
The ''install'' keyword can be used in command line to install gems. | |||
<pre> | |||
$ gem install capybara | |||
</pre> | |||
=== Uninstalling a Gem === | |||
The ''uninstall'' keyword can be used in command line to uninstall any existing gem in the system. | |||
<pre> | |||
$ gem uninstall capybara | |||
</pre> | |||
== | If you uninstall a dependency of a gem RubyGems will ask you for confirmation. | ||
<pre> | |||
$ gem uninstall rbtree | |||
You have requested to uninstall the gem: | |||
rbtree-0.4.1 | |||
drip-0.0.2 depends on rbtree (>= 0) | |||
If you remove this gem, these dependencies will not be met. | |||
Continue with Uninstall? [yN] n | |||
ERROR: While executing gem ... (Gem::DependencyRemovalException) | |||
Uninstallation aborted due to dependent gem(s) | |||
</pre> | |||
=== Update all existing Gems === | |||
The ''update'' keyword can be used in command line to update all existing gems in the system. | |||
<pre> | |||
$ gem update | |||
</pre> | |||
=== Creating a new Gem <ref>http://timelessrepo.com/making-ruby-gems Making Ruby Gems</ref> === | |||
It is also possible to [http://guides.rubygems.org/make-your-own-gem/ create our own ruby gem] to be used later to extend our Ruby applications. Bundler is a tool that can be used to [https://github.com/radar/guides/blob/master/gem-development.md to create a ruby gem]. | |||
=== Ruby Gem Commands === | |||
There is a list of commands that can be used with Ruby Gems. More details of each of these commands can be found [http://guides.rubygems.org/command-reference/ here] | |||
<pre> | |||
gem build | |||
gem cert | |||
gem check | |||
gem cleanup | |||
gem contents | |||
gem dependency | |||
gem environment | |||
gem fetch | |||
gem generate_index | |||
gem help | |||
gem install | |||
gem list | |||
gem lock | |||
gem mirror | |||
gem outdated | |||
gem owner | |||
gem pristine | |||
gem push | |||
gem query | |||
gem rdoc | |||
gem search | |||
gem server | |||
gem sources | |||
gem specification | |||
gem stale | |||
gem uninstall | |||
gem unpack | |||
gem update | |||
gem which | |||
gem yank | |||
</pre> | |||
== Useful Gems in RAILS environment == | |||
There are many gems which provide easy of functionality that can be included in the rails development environment. [http://bundler.io/ Bundler]is a useful gem that enables a developer to quickly add and manage gems in a few lines of code. | There are many gems which provide easy of functionality that can be included in the rails development environment. [http://bundler.io/ Bundler]is a useful gem that enables a developer to quickly add and manage gems in a few lines of code. | ||
Line 11: | Line 137: | ||
'''MODEL layer''' | '''MODEL layer''' | ||
'''Active Record Plugins''' | ==='''Active Record Plugins'''<ref>https://www.ruby-toolbox.com/categories/Active_Record_DB_Adapters</ref>=== | ||
* | * '''oracle-enhanced''' Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases. This adapter is superset of original ActiveRecord Oracle adapter. | ||
* | * '''activerecord-jdbc-adapter''' This adapter is build on JDBC API used for connecting to the database. AR-JDBC is a database adapter for Rails' ActiveRecord component. It allows to connect to virtually any JDBC-compliant database with your JRuby on Rails application. | ||
* | * '''nulldb''' This helps in Database simulation and testing. A database backend that translates database interactions into no-ops. We can test our model business logic with wanting to experiment with real database. | ||
* | * '''oracle-enhanced-enhanced''' It includes several enhancements and customization to the standard ActiveRecord Oracle Enhapnced adapter, which is still required. Any customization to this adapter's behavior or additional Oracle-specific utilities should be added here. | ||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/activerecord-sqlserver-adapter '''activerecord-sqlserver-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcmysql-adapter '''activerecord-jdbcmysql-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcpostgresql-adapter '''activerecord-jdbcpostgresql-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcderby-adapter '''activerecord-jdbcderby-adapter'''],. | * Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/activerecord-sqlserver-adapter '''activerecord-sqlserver-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcmysql-adapter '''activerecord-jdbcmysql-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcpostgresql-adapter '''activerecord-jdbcpostgresql-adapter'''], [https://www.ruby-toolbox.com/projects/activerecord-jdbcderby-adapter '''activerecord-jdbcderby-adapter'''],. | ||
'''Active Record Index Assistants''' | ==='''Active Record Index Assistants'''<ref>https://www.ruby-toolbox.com/categories/Active_Record_Index_Assistants</ref>=== | ||
* | * '''foreigner''' Adds helpers to migrations and dumps foreign keys to schema.rb. | ||
* | * '''rails_indexes''' A rake task to track down missing database indexes. does not assume that all foreign keys end with the convention of _id. | ||
* | * '''schema_plus''' SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views. | ||
* | * '''automatic_foreign_key''' Automatic Foreign Key automatically generates foreign-key constraints when creating tables or adding columns. It uses SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints. | ||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/ambitious_query_indexer '''ambitious_query_indexer'''], [https://www.ruby-toolbox.com/projects/lol_dba '''lol_dba'''], [https://www.ruby-toolbox.com/projects/immigrant '''immigrant'''], [https://www.ruby-toolbox.com/projects/redhillonrails_core '''redhillonrails_core''']. | * Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/ambitious_query_indexer '''ambitious_query_indexer'''], [https://www.ruby-toolbox.com/projects/lol_dba '''lol_dba'''], [https://www.ruby-toolbox.com/projects/immigrant '''immigrant'''], [https://www.ruby-toolbox.com/projects/redhillonrails_core '''redhillonrails_core''']. | ||
'''Rails DB Bootstrapping''' | ==='''Rails DB Bootstrapping'''<ref>https://www.ruby-toolbox.com/categories/rails_db_bootstrapping</ref>=== | ||
* | * '''seed-fu''' Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around. | ||
* | * '''populator''' Mass populate an Active Record database. | ||
* | * '''seedbank''' Extends Rails seeds to split out complex seeds into multiple files and lets each environment have it's own seeds. | ||
* | * '''Has alter ego''' has_alter_ego makes it possible to keep seed and live data transparently in parallel. In contrast to other seed data approaches has_alter_ego synchronizes the seed definitions with your database objects automagically unless you've overridden it in the database. | ||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/bootstrapper '''Bootstrapper'''], [https://www.ruby-toolbox.com/projects/ | * Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/bootstrapper '''Bootstrapper'''], [https://www.ruby-toolbox.com/projects/db-populate '''Db-populate'''], [https://www.ruby-toolbox.com/projects/seed_dumper '''seed_dumper'''], [https://www.ruby-toolbox.com/projects/dibber '''dibber''']. | ||
'''Rails Search''' | ==='''Rails Search'''<ref>https://www.ruby-toolbox.com/categories/rails_search</ref>=== | ||
* | * '''Sunspot''' Sunspot is a library providing a powerful, all-ruby API for the Solr search engine. Sunspot manages the configuration of persistent Ruby classes for search and indexing and exposes Solr's most powerful features through a collection of DSLs. Complex search operations can be performed without hand-writing any boolean queries or building Solr parameters by hand. | ||
* | * '''sunspot_rails''' Sunspot::Rails is an extension to the Sunspot library for Solr search. Sunspot::Rails adds integration between Sunspot and ActiveRecord, including defining search and indexing related methods on ActiveRecord models themselves, running a Sunspot-compatible Solr instance for development and test environments, and automatically commit Solr index changes at the end of each Rails request. | ||
* | * '''Tire''' Tire is a Ruby client for the Elasticsearch search engine/database. It provides Ruby-like API for fluent communication with the Elasticsearch server and blends with ActiveModel class for convenient usage in Rails applications. It allows to delete and create indices, define mapping for them, supports the bulk API, and presents an easy-to-use DSL for constructing your queries. It has full ActiveRecord/ActiveModel compatibility, allowing you to index your models (incrementally upon saving, or in bulk), searching and paginating the results. | ||
* | * '''thinking-sphinx''' An intelligent layer for ActiveRecord (via Rails and Sinatra) for the Sphinx full-text search tool. | ||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/pg_search '''pg_search'''], [https://www.ruby-toolbox.com/projects/redis-search '''redis-search'''], [https://www.ruby-toolbox.com/projects/ferret '''Ferret'''], [https://www.ruby-toolbox.com/projects/searchlight '''searchlight''']. | * Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/pg_search '''pg_search'''], [https://www.ruby-toolbox.com/projects/redis-search '''redis-search'''], [https://www.ruby-toolbox.com/projects/ferret '''Ferret'''], [https://www.ruby-toolbox.com/projects/searchlight '''searchlight''']. | ||
'''Data Persistence''' | ==='''Data Persistence'''<ref>https://www.ruby-toolbox.com/#Data_Persistence</ref>=== | ||
* | * '''Mongoid''' Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby. | ||
* | * '''Mongomatic''' Mongomatic is a modular Ruby object mapper for Mongo. | ||
* | * '''dynamoid''' Dynamoid is an ORM for Amazon's DynamoDB that supports offline development, associations, querying, and everything else you'd expect from an ActiveRecord-style replacement. | ||
* | * '''squeel''' Squeel unlocks the power of Arel in your Rails 3 application with a handy block-based syntax. You can write subqueries, access named functions provided by your RDBMS, and more, all without writing SQL strings. | ||
'''VIEW layer''' | '''VIEW layer''' | ||
'''CSS''' | ==='''CSS'''<ref>https://www.ruby-toolbox.com/categories/css_with_ruby</ref>=== | ||
* | * '''Sass''' Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a web-framework plugin. | ||
* | * '''bourbon''' The purpose of Bourbon Vanilla Sass Mixins is to provide a comprehensive framework of sass mixins that are designed to be as vanilla as possible. Meaning they should not deter from the original CSS syntax. The mixins contain vendor specific prefixes for all CSS3 properties for support amongst modern browsers. The prefixes also ensure graceful degradation for older browsers that support only CSS3 prefixed properties. | ||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/less '''Less'''], [https://www.ruby-toolbox.com/projects/sass-rails '''sass-rails'''], [https://www.ruby-toolbox.com/projects/stylus '''stylus'''], [https://www.ruby-toolbox.com/projects/patterns '''patterns'''] | * Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/less '''Less'''], [https://www.ruby-toolbox.com/projects/sass-rails '''sass-rails'''], [https://www.ruby-toolbox.com/projects/stylus '''stylus'''], [https://www.ruby-toolbox.com/projects/patterns '''patterns'''] | ||
'''Graphing''' | ==='''Graphing'''<ref>https://www.ruby-toolbox.com/categories/css_with_ruby</ref>=== | ||
* | * '''google_visualr''' This Ruby gem, GoogleVisualr, is a wrapper around the Google Chart Tools that allows anyone to create the same beautiful charts with just Ruby; you don't have to write any JavaScript at all. | ||
* | * '''highcharts-rails''' Gem that includes Highcharts (Interactive JavaScript charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1. | ||
* | * '''Seer''' Gem that includes Highcharts (Interactive JavaScript charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1.Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts. | ||
'''HTML & Markup''' | ==='''HTML & Markup'''<ref>https://www.ruby-toolbox.com/categories/rails_form_builders</ref>=== | ||
* | * '''formula''' Formula is a Rails form generator that generates simple clean markup. The project aims to let users create semantically beautiful forms without introducing too much syntax. The goal is to make integrating advanced layout systems as simple as possible. | ||
* | * '''Formtastic''' A Rails form builder plugin/gem with semantically rich and accessible markup. | ||
'''JavaScript''' | ==='''JavaScript'''<ref>https://www.ruby-toolbox.com/categories/javascript_testing</ref>=== | ||
* | * '''Jasmine''' Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax. | ||
* | * '''konacha''' Konacha is a Rails engine that allows you to test your JavaScript with the mocha test framework and chai assertion library. It is similar to Jasmine and Evergreen, but does not attempt to be framework agnostic. By sticking with Rails, Konacha can take full advantage of features such as the asset pipeline and engines | ||
'''Rails In-Place Editing''' | ==='''Rails In-Place Editing'''<ref>https://www.ruby-toolbox.com/categories/rails_in_place_editing</ref>=== | ||
* | * '''BestInPlace''' BestInPlace is a jQuery script and a Rails 3 helper that provide the method best_in_place to display any object field easily editable for the user by just clicking on it. It supports input data, text data, boolean data and custom dropdown data. It works with RESTful controllers. | ||
* | * '''best_in_place_mongoid''' BestInPlaceMongoid is a fork of BestInPlace jQuery script and a Rails 3 helper that provide the method best_in_place to display any object field easily editable for the user by just clicking on it. It supports input data, text data, boolean data and custom dropdown data. It works with RESTful controllers. | ||
'''CONTROLLER layer''' | '''CONTROLLER layer''' | ||
==='''Background Jobs'''<ref>https://www.ruby-toolbox.com/categories/Background_Jobs</ref>=== | |||
* '''Resque''' Resque is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later. Background jobs can be any Ruby class or module that responds to perform. Your existing classes can easily be converted to background jobs or you can create new classes specifically to do work. Or, you can do both. Resque is heavily inspired by DelayedJob (which rocks) and is comprised of three parts: * A Ruby library for creating, querying, and processing jobs * A Rake task for starting a worker which processes jobs * A Sinatra app for monitoring queues, jobs, and workers. | |||
* '''Starling''' Starling is a light-weight, persistent queue server that speaks the memcached protocol. It was originally developed for Twitter's backend. | |||
==='''Scheduling'''<ref>https://www.ruby-toolbox.com/categories/scheduling</ref>=== | |||
* '''resque-scheduler''' Light weight job scheduling on top of Resque. Adds methods enqueue_at/enqueue_in to schedule jobs in the future. Also supports queueing jobs on a fixed, cron-like schedule. | |||
* '''Clockwork''' A scheduler process to replace cron, using a more flexible Ruby syntax running as a single long-running process. Inspired by rufus-scheduler and resque-scheduler. | |||
==='''Code Metrics'''<ref>https://www.ruby-toolbox.com/categories/code_metrics</ref>=== | |||
* '''SimpleCov''' Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites. | |||
* '''Flay''' Flay analyzes code for structural similarities. Differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc are all ignored. Making this totally rad. | |||
==='''E-Mail Sending'''<ref>https://www.ruby-toolbox.com/categories/e_mail</ref>=== | |||
* '''Action Mailer''' Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments. | |||
* '''capistrano_mailer''' Capistrano Deployment Email Notification. Keep the whole team informed of each release! | |||
'''TESTING''' | |||
==='''Browser testing'''<ref>https://www.ruby-toolbox.com/categories/browser_testing</ref>=== | |||
* '''Capybara''' Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website. | |||
* '''Webrat''' Webrat lets you quickly write expressive and robust acceptance tests for a Ruby web application. It supports simulating a browser inside a Ruby process to avoid the performance hit and browser dependency of Selenium or Watir, but the same API can also be used to drive real Selenium tests when necessary (eg. for testing AJAX interactions). Most Ruby web frameworks and testing frameworks are supported. | |||
==='''Random Data Generation'''<ref>https://www.ruby-toolbox.com/categories/random_data_generation</ref>=== | |||
* '''Faker''' Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc. | |||
* '''Forgery''' Easy and customizable generation of forged data. Can be used as a gem or a rails plugin. Includes rails generators for creating your own forgeries. | |||
==='''Unit Test Frameworks'''<ref>https://www.ruby-toolbox.com/categories/testing_frameworks</ref>=== | |||
* '''test-unit''' Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit bundled in Ruby 1.8.x had not been improved but unbundled Test::Unit (test-unit) is improved actively. | |||
* '''Wrong''' Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail. The Wrong idea is to replace all those countless assert_this, assert_that library methods which only exist to give a more useful failure message than "assertion failed". Wrong replaces all of them in one fell swoop, since if you can write it in Ruby, Wrong can make a sensible failure message out of it. Also provided are several helper methods, like rescuing, capturing, and d. | |||
* Other useful Ruby Gems here. [https://www.ruby-toolbox.com/projects/testrocket '''testrocket'''], [https://www.ruby-toolbox.com/projects/kintama '''kintama'''], [https://www.ruby-toolbox.com/projects/lemon '''Lemon'''], [https://www.ruby-toolbox.com/projects/shindo '''Shindo''']. | |||
== See Also == | |||
[http://guides.rubygems.org/make-your-own-gem/ Gudie to create your own Ruby Gem]<br> | |||
[http://rubygems.rubyforge.org/rubygems-update/UPGRADING_rdoc.html How to Upgrade/Downgrade Ruby Gems]<br> | |||
[http://rubylearning.com/blog/ Collection of Ruby Study Notes]<br> | |||
[http://net.tutsplus.com/articles/web-roundups/24-extremely-useful-ruby-gems-for-web-development/ 24 extremely useful Ruby Gems for web development]<br> | |||
[http://railscasts.com/episodes/245-new-gem-with-bundler Screencasts to create a Ruby Gem]<br> | |||
[http://guides.rubygems.org/publishing/ How to publish your Ruby Gem?]<br> | |||
[http://www.ibm.com/developerworks/aix/library/au-aix-manage-ruby/ Manage Ruby and Gems with rvm]<br> | |||
[http://railscasts.com/episodes/183-gemcutter-jeweler Gemcutter and Jeweler railscast]<br> | |||
[https://www.ruby-toolbox.com/projects/factory_girl Ruby Gem - factory girl]<br> | |||
[http://railscasts.com/episodes/192-authorization-with-cancan?view=asciicast Using cancan for authorization] | |||
[https://www.ruby-toolbox.com Ruby Tool Box] | |||
[https://rubyforge.org/ Ruby Forge by Ruby Central] | |||
== References== | |||
<references /> |
Latest revision as of 23:29, 25 September 2013
Ruby Gem is a package manager for Ruby programming language. It allows users to easily download, install and use software packages on their system. The functionality of a Ruby application can be modified or extended with the help of Gems. In the version 1.9 of Ruby, Ruby Gems has been made a part of the standard library. This article would take the user on a tour of what ruby gems are all about and introduce the reader to various Ruby gems one can use to extend a Ruby application. Links for more details on Ruby gems are provided for the reader's benefit at the end of the article.
A Tour of Ruby Gems
Definition of a Ruby Gem<ref>http://guides.rubygems.org/rubygems-basics/#installing_gems Ruby Gems guide</ref>
In simple terms, a Ruby Gem is a package containing files that can be installed in a system and can help expand the functionality of a Ruby application. Ruby gems are very powerful. Ruby programmers create and publish Ruby Gems as open source in github. It is very easy to install, upgrade and delete Gems in a system.
Structure of Ruby Gem
Every Gem has a set of files and the following standard structure
$ tree -d newgem |-- lib/ | |-- newgem.rb | `-- newgem/ | |-- base.rb | `-- version.rb |-- test/ |-- bin/ |-- Rakefile `-- newgem.gemspec
The lib folder has the code of the ruby gem. It has newgem.rb file and a folder named newgem. This folder has two files which are base.rb and version.rb. The version number is recorded in version.rb and can be changed when the gem is updated. The bin directory has any binaries that is a part of the gem file and should be distributed with the gem. A gem usually has a Rakefile. The rake program uses this to generate code and automate tests in addition to performing other tasks. The Gem specification file newgem.gemspec contains details specific to the gem. The file has details such as the gem name,the files that are in it, the gems it depends on for performing testing, the gems it depends on for actually running and other details.
Listing existing Gems
To list the existing gems in a system list keyword can be used in the command line.
$ gem list *** LOCAL GEMS *** actionmailer (3.2.3) actionpack (3.2.3) activemodel (3.2.3) activerecord (3.2.3) activeresource (3.2.3) activesupport (3.2.3) arel (3.0.2) bigdecimal (1.1.0) builder (3.0.4) bundler (1.3.5) capybara (2.1.0) coffee-rails (3.2.2) coffee-script (2.2.0) coffee-script-source (1.6.3) erubis (2.7.0) execjs (2.0.1) hike (1.2.3) i18n (0.6.5) io-console (0.3) journey (1.0.4) jquery-rails (3.0.4)
Installing a new Gem
The install keyword can be used in command line to install gems.
$ gem install capybara
Uninstalling a Gem
The uninstall keyword can be used in command line to uninstall any existing gem in the system.
$ gem uninstall capybara
If you uninstall a dependency of a gem RubyGems will ask you for confirmation.
$ gem uninstall rbtree You have requested to uninstall the gem: rbtree-0.4.1 drip-0.0.2 depends on rbtree (>= 0) If you remove this gem, these dependencies will not be met. Continue with Uninstall? [yN] n ERROR: While executing gem ... (Gem::DependencyRemovalException) Uninstallation aborted due to dependent gem(s)
Update all existing Gems
The update keyword can be used in command line to update all existing gems in the system.
$ gem update
Creating a new Gem <ref>http://timelessrepo.com/making-ruby-gems Making Ruby Gems</ref>
It is also possible to create our own ruby gem to be used later to extend our Ruby applications. Bundler is a tool that can be used to to create a ruby gem.
Ruby Gem Commands
There is a list of commands that can be used with Ruby Gems. More details of each of these commands can be found here
gem build gem cert gem check gem cleanup gem contents gem dependency gem environment gem fetch gem generate_index gem help gem install gem list gem lock gem mirror gem outdated gem owner gem pristine gem push gem query gem rdoc gem search gem server gem sources gem specification gem stale gem uninstall gem unpack gem update gem which gem yank
Useful Gems in RAILS environment
There are many gems which provide easy of functionality that can be included in the rails development environment. Bundleris a useful gem that enables a developer to quickly add and manage gems in a few lines of code.
We can classify the Gems based on the usage in different layers Model, View and Controller.
MODEL layer
Active Record Plugins<ref>https://www.ruby-toolbox.com/categories/Active_Record_DB_Adapters</ref>
- oracle-enhanced Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases. This adapter is superset of original ActiveRecord Oracle adapter.
- activerecord-jdbc-adapter This adapter is build on JDBC API used for connecting to the database. AR-JDBC is a database adapter for Rails' ActiveRecord component. It allows to connect to virtually any JDBC-compliant database with your JRuby on Rails application.
- nulldb This helps in Database simulation and testing. A database backend that translates database interactions into no-ops. We can test our model business logic with wanting to experiment with real database.
- oracle-enhanced-enhanced It includes several enhancements and customization to the standard ActiveRecord Oracle Enhapnced adapter, which is still required. Any customization to this adapter's behavior or additional Oracle-specific utilities should be added here.
- Other useful Ruby Gems here. activerecord-sqlserver-adapter, activerecord-jdbcmysql-adapter, activerecord-jdbcpostgresql-adapter, activerecord-jdbcderby-adapter,.
Active Record Index Assistants<ref>https://www.ruby-toolbox.com/categories/Active_Record_Index_Assistants</ref>
- foreigner Adds helpers to migrations and dumps foreign keys to schema.rb.
- rails_indexes A rake task to track down missing database indexes. does not assume that all foreign keys end with the convention of _id.
- schema_plus SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views.
- automatic_foreign_key Automatic Foreign Key automatically generates foreign-key constraints when creating tables or adding columns. It uses SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints.
- Other useful Ruby Gems here. ambitious_query_indexer, lol_dba, immigrant, redhillonrails_core.
Rails DB Bootstrapping<ref>https://www.ruby-toolbox.com/categories/rails_db_bootstrapping</ref>
- seed-fu Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
- populator Mass populate an Active Record database.
- seedbank Extends Rails seeds to split out complex seeds into multiple files and lets each environment have it's own seeds.
- Has alter ego has_alter_ego makes it possible to keep seed and live data transparently in parallel. In contrast to other seed data approaches has_alter_ego synchronizes the seed definitions with your database objects automagically unless you've overridden it in the database.
- Other useful Ruby Gems here. Bootstrapper, Db-populate, seed_dumper, dibber.
Rails Search<ref>https://www.ruby-toolbox.com/categories/rails_search</ref>
- Sunspot Sunspot is a library providing a powerful, all-ruby API for the Solr search engine. Sunspot manages the configuration of persistent Ruby classes for search and indexing and exposes Solr's most powerful features through a collection of DSLs. Complex search operations can be performed without hand-writing any boolean queries or building Solr parameters by hand.
- sunspot_rails Sunspot::Rails is an extension to the Sunspot library for Solr search. Sunspot::Rails adds integration between Sunspot and ActiveRecord, including defining search and indexing related methods on ActiveRecord models themselves, running a Sunspot-compatible Solr instance for development and test environments, and automatically commit Solr index changes at the end of each Rails request.
- Tire Tire is a Ruby client for the Elasticsearch search engine/database. It provides Ruby-like API for fluent communication with the Elasticsearch server and blends with ActiveModel class for convenient usage in Rails applications. It allows to delete and create indices, define mapping for them, supports the bulk API, and presents an easy-to-use DSL for constructing your queries. It has full ActiveRecord/ActiveModel compatibility, allowing you to index your models (incrementally upon saving, or in bulk), searching and paginating the results.
- thinking-sphinx An intelligent layer for ActiveRecord (via Rails and Sinatra) for the Sphinx full-text search tool.
- Other useful Ruby Gems here. pg_search, redis-search, Ferret, searchlight.
Data Persistence<ref>https://www.ruby-toolbox.com/#Data_Persistence</ref>
- Mongoid Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
- Mongomatic Mongomatic is a modular Ruby object mapper for Mongo.
- dynamoid Dynamoid is an ORM for Amazon's DynamoDB that supports offline development, associations, querying, and everything else you'd expect from an ActiveRecord-style replacement.
- squeel Squeel unlocks the power of Arel in your Rails 3 application with a handy block-based syntax. You can write subqueries, access named functions provided by your RDBMS, and more, all without writing SQL strings.
VIEW layer
CSS<ref>https://www.ruby-toolbox.com/categories/css_with_ruby</ref>
- Sass Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
- bourbon The purpose of Bourbon Vanilla Sass Mixins is to provide a comprehensive framework of sass mixins that are designed to be as vanilla as possible. Meaning they should not deter from the original CSS syntax. The mixins contain vendor specific prefixes for all CSS3 properties for support amongst modern browsers. The prefixes also ensure graceful degradation for older browsers that support only CSS3 prefixed properties.
- Other useful Ruby Gems here. Less, sass-rails, stylus, patterns
Graphing<ref>https://www.ruby-toolbox.com/categories/css_with_ruby</ref>
- google_visualr This Ruby gem, GoogleVisualr, is a wrapper around the Google Chart Tools that allows anyone to create the same beautiful charts with just Ruby; you don't have to write any JavaScript at all.
- highcharts-rails Gem that includes Highcharts (Interactive JavaScript charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1.
- Seer Gem that includes Highcharts (Interactive JavaScript charts for your web projects), in the Rails Asset Pipeline introduced in Rails 3.1.Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts.
HTML & Markup<ref>https://www.ruby-toolbox.com/categories/rails_form_builders</ref>
- formula Formula is a Rails form generator that generates simple clean markup. The project aims to let users create semantically beautiful forms without introducing too much syntax. The goal is to make integrating advanced layout systems as simple as possible.
- Formtastic A Rails form builder plugin/gem with semantically rich and accessible markup.
JavaScript<ref>https://www.ruby-toolbox.com/categories/javascript_testing</ref>
- Jasmine Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.
- konacha Konacha is a Rails engine that allows you to test your JavaScript with the mocha test framework and chai assertion library. It is similar to Jasmine and Evergreen, but does not attempt to be framework agnostic. By sticking with Rails, Konacha can take full advantage of features such as the asset pipeline and engines
Rails In-Place Editing<ref>https://www.ruby-toolbox.com/categories/rails_in_place_editing</ref>
- BestInPlace BestInPlace is a jQuery script and a Rails 3 helper that provide the method best_in_place to display any object field easily editable for the user by just clicking on it. It supports input data, text data, boolean data and custom dropdown data. It works with RESTful controllers.
- best_in_place_mongoid BestInPlaceMongoid is a fork of BestInPlace jQuery script and a Rails 3 helper that provide the method best_in_place to display any object field easily editable for the user by just clicking on it. It supports input data, text data, boolean data and custom dropdown data. It works with RESTful controllers.
CONTROLLER layer
Background Jobs<ref>https://www.ruby-toolbox.com/categories/Background_Jobs</ref>
- Resque Resque is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later. Background jobs can be any Ruby class or module that responds to perform. Your existing classes can easily be converted to background jobs or you can create new classes specifically to do work. Or, you can do both. Resque is heavily inspired by DelayedJob (which rocks) and is comprised of three parts: * A Ruby library for creating, querying, and processing jobs * A Rake task for starting a worker which processes jobs * A Sinatra app for monitoring queues, jobs, and workers.
- Starling Starling is a light-weight, persistent queue server that speaks the memcached protocol. It was originally developed for Twitter's backend.
Scheduling<ref>https://www.ruby-toolbox.com/categories/scheduling</ref>
- resque-scheduler Light weight job scheduling on top of Resque. Adds methods enqueue_at/enqueue_in to schedule jobs in the future. Also supports queueing jobs on a fixed, cron-like schedule.
- Clockwork A scheduler process to replace cron, using a more flexible Ruby syntax running as a single long-running process. Inspired by rufus-scheduler and resque-scheduler.
Code Metrics<ref>https://www.ruby-toolbox.com/categories/code_metrics</ref>
- SimpleCov Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites.
- Flay Flay analyzes code for structural similarities. Differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc are all ignored. Making this totally rad.
E-Mail Sending<ref>https://www.ruby-toolbox.com/categories/e_mail</ref>
- Action Mailer Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments.
- capistrano_mailer Capistrano Deployment Email Notification. Keep the whole team informed of each release!
TESTING
Browser testing<ref>https://www.ruby-toolbox.com/categories/browser_testing</ref>
- Capybara Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website.
- Webrat Webrat lets you quickly write expressive and robust acceptance tests for a Ruby web application. It supports simulating a browser inside a Ruby process to avoid the performance hit and browser dependency of Selenium or Watir, but the same API can also be used to drive real Selenium tests when necessary (eg. for testing AJAX interactions). Most Ruby web frameworks and testing frameworks are supported.
Random Data Generation<ref>https://www.ruby-toolbox.com/categories/random_data_generation</ref>
- Faker Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.
- Forgery Easy and customizable generation of forged data. Can be used as a gem or a rails plugin. Includes rails generators for creating your own forgeries.
Unit Test Frameworks<ref>https://www.ruby-toolbox.com/categories/testing_frameworks</ref>
- test-unit Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit bundled in Ruby 1.8.x had not been improved but unbundled Test::Unit (test-unit) is improved actively.
- Wrong Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail. The Wrong idea is to replace all those countless assert_this, assert_that library methods which only exist to give a more useful failure message than "assertion failed". Wrong replaces all of them in one fell swoop, since if you can write it in Ruby, Wrong can make a sensible failure message out of it. Also provided are several helper methods, like rescuing, capturing, and d.
- Other useful Ruby Gems here. testrocket, kintama, Lemon, Shindo.
See Also
Gudie to create your own Ruby Gem
How to Upgrade/Downgrade Ruby Gems
Collection of Ruby Study Notes
24 extremely useful Ruby Gems for web development
Screencasts to create a Ruby Gem
How to publish your Ruby Gem?
Manage Ruby and Gems with rvm
Gemcutter and Jeweler railscast
Ruby Gem - factory girl
Using cancan for authorization
Ruby Tool Box
Ruby Forge by Ruby Central
References
<references />