devroom.io/drafts/2012-04-02-showing-ruby-rails-and-git-info-in-your-app.md
Ariejan de Vroom dbae98c4c0 Moar updates
2013-03-24 14:27:51 +01:00

1.8 KiB

title kind slug created_at tags
Showing Ruby, Rails and git info in your app article showing-ruby-rails-and-git-info-in-your-app 2012-04-02
Ruby
Rails
protip

Some people've asked me how I show rendering information on ariejan.net.

There are a few things going on here, let me explain them one by one.

Rails version

The current Rails version is probably the easiest you see here. Rails exposes its version information like this:

:::ruby
Rails.version

Ruby version

Ruby also exposes version information, albeit using constants:

:::ruby
RUBY_VERSION
=> "1.9.3"

You may know that ruby also has different patch levels for each release. You can also retrieve that information:

:::ruby
RUBY_PATCHLEVEL
=> 125

The you may also want to know which engine you're using. This may be "ruby" or something different:

:::ruby
RUBY_ENGINE
=> "ruby"

Combine these to get a sexy ruby version string:

:::ruby
puts "#{RUBY_ENGINE}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
=> "ruby-1.9.3-p125"

Current process ID

I like to know which Unicorn produced a certain page. Retrieving the process ID is easy:

:::ruby
Process.pid
=> 9473

Current git revision SHA

Knowing which version of your app is currently running can be useful information. To do this I created the following initializer:

:::ruby
# config/initializers/git_revision.rb
module AppName
  REVISION = `git log --pretty=format:'%h' -n 1`
end

This will expose the current short SHA in your application's namespace:

:::ruby
AppName::REVISION
=> "ac6d3a0"

You can now use this info through-out your app to show version information.