CSC/ECE 517 Fall 2013/ch1 1w24 nv

From Expertiza_Wiki
Revision as of 10:50, 15 September 2013 by Npari (talk | contribs) (→‎References)
Jump to navigation Jump to search

Ruby Gem is a package manager for Ruby programming language. It allows users to easily download, install and use software packages on their system. Gems are used to extend or modify the functionality of an existing Ruby application. Ruby Gems has been made a part of the standard library of Ruby version 1.9.

A Tour of Ruby Gems

Definition of a Ruby Gem

Structure of Ruby Gem

Every Gem has the following standard structure

$ tree -d mygem
|-- lib/
|   |-- mygem.rb
|   `-- mygem/
|       |-- base.rb
|       `-- version.rb
|-- test/
|-- bin/
|-- Rakefile
`-- mygem.gemspec

The code of the ruby gem goes under the lib folder. It has mygem.rb file and a folder named mygem inside which there is base.rb and version.rb. The version number is stored in version.rd. The bin directory holds any binaries that should be distributed with the gem. A gem usually has a Rakefile, which the rake program uses to automate tests, generate code, and perform other tasks. The Gem specification file mygem.gemspec contains details about the gem such as the name of the gem,the files that are in it, the gems it depends on for 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)

Some important Gems that are useful 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

  • 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 AR-JDBC is a database adapter for Rails' ActiveRecord component designed to be used with JRuby built upon Java's JDBC API for database access. It allows to connect to virtually any JDBC-compliant database with your JRuby on Rails application.
  • nulldb A database backend that translates database interactions into no-ops. Using NullDB enables you to test your model business logic - without ever touching a real database.
  • oracle-enhanced-enhanced It includes several enhancements and customization to the standard ActiveRecord Oracle Enhanced adapter, which is still required. Any customization to this adapter's behavior or additional Oracle-specific utilities should be added here.

Active Record Index Assistants

  • 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.

Rails DB Bootstrapping

  • 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.

Rails Search

  • 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.

Data Persistence

  • 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

  • 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.

Graphing

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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.

See Also

How to Upgrade/Downgrade Ruby Gems
Ruby Learning

References

1. www.rubygems.org
2. www.timelessrepo.com
3. [1]