# Advices on Rake tasks organization

**URL:** <https://www.ruby-forum.com/t/advices-on-rake-tasks-organization/146143>\
**Category:** Ruby\
**Created:** [August 18, 2008, 1:57pm UTC](https://www.ruby-forum.com/t/advices-on-rake-tasks-organization/146143 "2008-08-18T13:57:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Philippe\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@Jean-Philippe\_M](https://www.ruby-forum.com/u/Jean-Philippe_M)\
**Post date:** [August 18, 2008, 1:57pm UTC](https://www.ruby-forum.com/t/advices-on-rake-tasks-organization/146143/1 "2008-08-18T13:57:32Z")

</div>

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 M.
