Posts

Showing posts with the label Development

Writing usable scripts in Ruby

Usable command line tools/scripts There are a lot of command line tools written in ruby, python, bash, c or any other languages. They are usable simply because there is a standard way in dealing with them this way can be summarized in the following points: There has to be a usage example/brief help at the finger tips of the user ( by running with  -- help      or -h) arguments should have default values which are explained in the help misusage or missing mandatory arguments should fire the help message ruby tools OptionParser  is part of the standard library in ruby that takes care of this script packaging.  they show long and short examples This is an example of the script: require 'optparse' options = {} OptionParser.new do |opts| opts.banner = "Usage: script_name.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|   options[:verbose] = v end end.parse! p options p ARGV # Actual script co...

Rails 3 "couldn't parse YAML" error suddenly showing up

I have been developing on the latest Rails 3, Ruby 1.9.2 for a while. and suddenly in 2 projects I started to get this YAML loading error when I try to start my server or run the tests. bundler./home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 55 column 12 (Psych::SyntaxError) from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:148:in `parse_stream' from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:119:in `parse' from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:106:in `load' It turned out to be related to my recent upgrade of bundler to 1.0.10 After this update, my database.yml was not considered a valid YAML file. until I realized I have to put the special character values (for example: asd@#$asdf@$@) between double quotes. This fixed the problem for now I also came across another approach that basically will use a different YAML engine, This is wi...