| Module | Configatron::Rails |
| In: |
lib/configatron/rails.rb
|
Helpful for making using configatron with Rails even easier!
To get started you can use the generator to generate the necessary stub files.
$ ruby script/generate configatron
Loads configatron files in the following order:
Example:
<RAILS_ROOT>/config/configatron/defaults.rb <RAILS_ROOT>/config/configatron/<RAILS_ENV>.rb # optional: <RAILS_ROOT>/config/configatron/<RAILS_ENV>/defaults.rb <RAILS_ROOT>/config/configatron/<RAILS_ENV>/bar.rb <RAILS_ROOT>/config/configatron/<RAILS_ENV>/foo.rb
# File lib/configatron/rails.rb, line 19
19: def self.init(root = nil, env = nil)
20: base_dir = root
21: if root.nil?
22: root = defined?(RAILS_ROOT) ? RAILS_ROOT : FileUtils.pwd
23: base_dir = File.expand_path(File.join(root, 'config', 'configatron'))
24: end
25:
26: if env.nil?
27: env = defined?(RAILS_ENV) ? RAILS_ENV : 'development'
28: end
29:
30: config_files = []
31:
32: config_files << File.join(base_dir, 'defaults.rb')
33: config_files << File.join(base_dir, "#{env}.rb")
34:
35: env_dir = File.join(base_dir, env)
36: config_files << File.join(env_dir, 'defaults.rb')
37:
38: Dir.glob(File.join(env_dir, '*.rb')).sort.each do |f|
39: config_files << f
40: end
41:
42: config_files.collect! {|config| File.expand_path(config)}.uniq!
43:
44: config_files.each do |config|
45: if File.exists?(config)
46: # puts "Configuration: #{config}"
47: require config
48: end
49: end
50: end