Tag Archives: ruby

Improve your Ruby code quality with metrics

In the ruby world we have several tools to analyse our ruby (and Rails) code. In this article we will see the most used (and useful for me), and how to integrate into our CI process with Jenkins.

These gems are:

In your Gemfile you should include all gems:

 # Metrics
 gem 'simplecov', require: false
 gem 'simplecov-rcov', require: false
 gem 'rubocop', require: false
 gem 'rails_best_practices', require: false
 gem 'metric_fu', require: false

Simplecov needs some configuration at the beginning of your ‘spec_helper.rb’ to generate the coverage files:

require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start 'rails'

That’s all done in your Rails project. Now you need to install two plugins in your Jenkins server:

Finally I have configured my metrics build as:

build-configuration

 

 

PRUN: Ruby server with Docker

logo-plumbadge

The idea is that: as equivalent to LAMP (Linux/Apache/Mysql/Php) architecture, in Ruby world we could have

PRUN architecture: Postgresql + Ruby + Ubuntu + Nginx.

Name: ‘Prun’ means ‘Plum’ in Romanian language.

I have used Docker to create a container with:

  • Ubuntu 14.04 trusty
  • Postgres 9.3
  • Ruby 2.1.2
  • Nginx 1.4.6

Also based on OpenSSH to connect, Chef to manage Rails apps configurations and Supervisor to maintain daemons at the container.

The repo is published on https://github.com/jlebrijo/prun and you can see the image at Docker hub https://registry.hub.docker.com/u/jlebrijo/prun/

The basic operation should be (details in the next post):

  1. Install with Docker: docker run -d -p 2222:22 -i jlebrijo/prun
  2. Manage configuration with Chef: knife solo cook root@lebrijo.com -p 2222
  3. Deploy with Capistrano: cap production deploy

That easy!!

Install RVM in your Ubuntu Desktop

You can install RVM with this few commands:

sudo apt-get install curl
curl -L get.rvm.io | bash -s stable --auto
source /etc/profile.d/rvm.sh << or whatever says the console of rvm >>

After that, you need to check which RVM prerequisites depends on :

rvm requirements

Install last ruby version:

rvm install 2.1.2

For .bashrc executing purposes, and execute RVM ruby version when open a project, you can integrate RVM with your Gnome terminal:

RVM gnome-terminal integration
Deeper explanation here: https://rvm.io/integration/gnome-terminal/

My favourite way to configure a Rails project ruby-version and gemset is in Gemfile:

#ruby=ruby-2.1.2
#ruby-gemset=website

But you always you can use .ruby-version and .ruby-gemset files.