Sha256: eb9a0535df618106b5832bb4c1a20c49e60015a7065b49547148eddb5094d68b

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

class Configatron
  # 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
  module Rails
    
    # 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
    def self.init(root = RAILS_ROOT)
      config_files = []

      base_dir = File.expand_path(File.join(root, 'config', 'configatron'))
      config_files << File.join(base_dir, 'defaults.rb')
      config_files << File.join(base_dir, "#{RAILS_ENV}.rb")

      env_dir = File.join(base_dir, RAILS_ENV)
      config_files << File.join(env_dir, 'defaults.rb')

      Dir.glob(File.join(env_dir, '*.rb')).sort.each do |f|
        config_files << f
      end

      config_files.collect! {|config| File.expand_path(config)}.uniq!

      config_files.each do |config|
        if File.exists?(config)
          # puts "Configuration: #{config}"
          require config
        end
      end
    end
    
  end # Rails
end # Configatron

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
markbates-configatron-2.4.1.20090826153428 lib/configatron/rails.rb
configatron-2.4.1 lib/configatron/rails.rb