Archive for 'Ruby'

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

I hardly ever use the local RDoc documentation of my installed Ruby gems. Typing in –no-rdoc –no-ri every time I install a gem is cumbersome. The gem takes longer to install and it uses up unnecessary disk space. That annoyance goes doubly when installing gems on a server.

Luckily, RubyGems allows to set default options in a file called .gemrc which should be placed in your home directory. The syntax is in YAML format, therefore straightforward for a Ruby programmer. Just add this line to .gemrc and you are golden.

    gem: --no-rdoc --no-ri
  

A list of all options can be found here.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Having a convenient way to store an applications configuration is something I want in every Ruby project. There are plenty of solutions for Ruby on Rails but none of them did really match my taste, because they did way too much. I wanted something simple that does not depend on Ruby on Rails and does not try to be too clever.

Here are my requirements for a configuration lib:

  • Nesting and namespaces
  • Simple string interpolation
  • Support for environments e.g testing, production, debug
  • Defaults for each environment

And this is what I came up with:

  • Use YAML (defaults, namespaces, scopes)
  • Parse the YAML file with ERB
  • Return an OpenStruct object for easy method accessors

The code and and information on how to install and use the lib can be found here: http://github.com/phuesler/simple_app_config

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]