Advices on Rake tasks organization

J

Jean-Philippe Moal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top