From: Jean-Philippe Moal Date: 2008-08-18T20:53:28+09:00 Subject: Advices on Rake tasks organization Hello, I am using some Rake tasks for various actions (from backup to project management) using this layout : |-- Rakefile |-- assets |-- config | |-- YAML files |-- lib | |-- parametres.rb `-- tasks |-- .rake files (for each namespace) The main Rakefile includes lib/ files and tasks/*.tasks files, define some task-related constants (ASSETS_PATH, formatted DATE...) then use the Parametres (I'm french :-)) class to parse the YAML files : class Parametres require "yaml" attr_accessor :parametres def initialize configsdir = defined?(RAKE_ROOT) ? RAKE_ROOT : ENV['PWD'] @parametres = {} Dir["#{configsdir}/config/*.yml"].each { |file| filename = File.basename(file, '.yml') unless filename.match(/\.server$/) @parametres[ filename.to_sym ] = open(file) { |f| YAML.load(f)} end } end end I would like some feedback on this organization, as I didn't find much information on this subject (except for rails-related tasks). At the moment I'm using a global variable to store an instance of Parametres : $config = Parametres.new.parametres This seems really ugly, but I don't know what would be better. Maybe a singleton should be used for Parametres ? My second question is more ruby related. In my Parametres class I'm building an instance variable @parametres with a hash filled with the YAML config files. So, for an ftp.yml file, I can use $config[:ftp][:login] for example. I could i use class attributes instead ? Like this : config = Parametres.new config.paths[:backup_dir] #maybe even config.paths.backup_dir ? Thanks, Jean-Philippe Moal