Tag: Ruby

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]

As part of the automated deployment process for a cocoa application, I needed to access a .plist file to change some values before the application gets bundled and uploaded.

Since plist files are plain XML files, I could have used something like libxml to get the job done but since this script runs on a Mac, I have access to RubyCocoa. That spares me the XML parsing and writing and gives me a simple persistent dictionary instead. This is what I ended up with:

I think that is pretty neat. However, I ran into a small pitfall when I tried to compare an NSString with a regular expression. I got this warning:

'NSString#=~' doesn't work correctly. Because it returns byte indexes.
    Please use 'String#=~' instead.

The solution is pretty simple, just call to_s on the dictionary values.

[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]