List of All/Best Gems for Ruby

List of installed gems?

The Gem command is included with Ruby 1.9+ now, and is a standard addition to Ruby pre-1.9.

require 'rubygems'

name = /^/i
dep = Gem::Dependency.new(name, Gem::Requirement.default)
specs = Gem.source_index.search(dep)
puts specs[0..5].map{ |s| "#{s.name} #{s.version}" }
# >> Platform 0.4.0
# >> abstract 1.0.0
# >> actionmailer 3.0.5
# >> actionpack 3.0.5
# >> activemodel 3.0.5
# >> activerecord 3.0.5

Here's an updated way to get a list:

require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

Because local_gems relies on group_by, it returns a hash of the gems, where the key is the gem's name, and the value is an array of the gem specifications. The value is an array of the instances of that gem that is installed, sorted by the version number.

That makes it possible to do things like:

my_local_gems = local_gems()

my_local_gems['actionmailer']
# => [Gem::Specification.new do |s|
# s.authors = ["David Heinemeier Hansson"]
# s.date = Time.utc(2013, 12, 3)
# s.dependencies = [Gem::Dependency.new("actionpack",
# Gem::Requirement.new(["= 4.0.2"]),
# :runtime),
# Gem::Dependency.new("mail",
# Gem::Requirement.new(["~> 2.5.4"]),
# :runtime)]
# s.description = "Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments."
# s.email = "david@loudthinking.com"
# s.homepage = "http://www.rubyonrails.org"
# s.licenses = ["MIT"]
# s.name = "actionmailer"
# s.require_paths = ["lib"]
# s.required_ruby_version = Gem::Requirement.new([">= 1.9.3"])
# s.requirements = ["none"]
# s.rubygems_version = "2.0.14"
# s.specification_version = 4
# s.summary = "Email composition, delivery, and receiving framework (part of Rails)."
# s.version = Gem::Version.new("4.0.2")
# end]

And:

puts my_local_gems.map{ |name, specs| 
[
name,
specs.map{ |spec| spec.version.to_s }.join(',')
].join(' ')
}
# >> actionmailer 4.0.2
...
# >> arel 4.0.1,5.0.0
...
# >> ZenTest 4.9.5
# >> zucker 13.1

The last example is similar to the gem query --local command-line, only you have access to all the information for a particular gem's specification.

What is the best Wiki Gem for Ruby on Rails?

There is no Wiki gem for Rails, per-se. What you do have are a few gems that will facilitate developing a Wiki much like what you're looking for here.

For versioning, I would recommend vestal_versions, and for rendering Markdown, I would recommend BlueCloth. Both of these gems have been out for a while, and are quite mature and well tested.

vestal_versions is also DB agnostic, as it piggybacks on ActiveRecord features, so it will work in whatever RDBMS you throw it at.

How do I list all versions of a gem available at a remote site?

Well, it was easier than I thought (well, not really, let's say as easy as it should be):

gem list rhc --remote --all

Which returns:

*** REMOTE GEMS ***
rhc (0.84.15, 0.84.13, 0.83.9, 0.82.18, 0.81.14, 0.80.5, 0.79.5, 0.77.8, 0.75.9, 0.74.6, 0.74.5, 0.73.14, 0.72.29, 0.71.2, 0.69.6, 0.69.3, 0.68.5)
rhcp (0.2.18, 0.2.17, 0.2.16, 0.2.15, 0.2.14, 0.1.9, 0.1.8, 0.1.7, 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2)
rhcp_shell (0.2.12, 0.2.11, 0.0.9, 0.0.7, 0.0.6, 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1)

Gems to assist in monitoring code quality

I use the following myself. I've found rubycritic particularly useful, and I believe it is the gem underlying a lot of the Code Climate reviews.

The sandi_meter is one I haven't used as much, but strongly encourages smaller methods.

I also strongly encourage using simplecov to help you evaluate your code coverage. Code coverage is by no means a panacea for any code problem, but it'll at least ensure that you do not miss segments of your code altogether.

The full list:

  gem 'traceroute' # Checks for undefined routes and unreachable actions.
gem 'bullet' # Checks for query optimizations.
gem 'rails_best_practices' # Checks for code optimization.
gem 'rubycritic' # Checks for code optimization.
gem 'sandi_meter' # Checks for compliance to Sandi Metz's rules for developers.
gem 'simplecov' #Enables coverage analysis of code.

How do I check all the gems with its versions in my Rails project?

Use

bundle list to show project related gems

To see some gems version, you can chain comands and use grep

exp.

bundle list | grep rails will list all gems that containt word rails, such as rails, jquery-rails, ...

versioning best practices for ruby gems

Unfortunately, if you dont' want you app to break because of backward-incompatible gem updates, you do have to specify gem versions. What I found to be a good practice is using the pessimistic operator ~> to specify gem versions. For example:

gem carrierwave, '~>0.6.0'

This means the carrierwave gem will be frozen at version 0.6, but bundle will install any minor, backward-compatible updates and bug fixes, which are usually increments of the last number (0.6.1, 0.6.2...). That means you can update your bundle without running the risk of breaking something (no more flinching when running bundle update).

You can also use the pessimistic operator on major versions:

gem devise, '~>2.0'

Meaning bundle will update to versions 2.1.0, 2.2.0, 2.2.1, 2.3.0, but never to 3.x.

Some considerations:

  1. You don't have to specify all gem versions, but it's good practice. I don't specify versions of my own gems, for example. But every third party gem has its version specified. Otherwise, I'd be trusting my code to things beyond my control.

  2. You still need to have a certain amount of trust in the gem maintainers to use the pessimistic operator. A reckless maintainer still could release backwards-incompatible changes in a minor version. In those cases, I lock the minor version (no pessimistic operator).

  3. If you specify gem versions, you'll be making bundle's work of resolving gem dependencies a lot easier, meaning it'll do it much faster.

What is a good shopping cart gem for Rails?

There is a wide range of payment and eCommerce gems covered at Railscasts.

A list of gems can also be found at The Ruby Toolbox and here too.

Also, not covered, you can use the Saas product Shopify



Related Topics



Leave a reply



Submit