Sha256: e5f67f040c08d0f232e20fc00dd241ca8c54bf055924c09e6f0e08c464862a77

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 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 = nil, env = nil)
      base_dir = root
      if root.nil?
        root = defined?(RAILS_ROOT) ? RAILS_ROOT : FileUtils.pwd
        base_dir = File.expand_path(File.join(root, 'config', 'configatron'))
      end
      
      if env.nil?
        env = defined?(RAILS_ENV) ? RAILS_ENV : 'development'
      end
      
      config_files = []

      config_files << File.join(base_dir, 'defaults.rb')
      config_files << File.join(base_dir, "#{env}.rb")

      env_dir = File.join(base_dir, 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

6 entries across 6 versions & 2 rubygems

Version Path
markbates-configatron-2.4.2.20090909140253 lib/configatron/rails.rb
markbates-configatron-2.5.0.20090910111951 lib/configatron/rails.rb
configatron-2.6.0 lib/configatron/rails.rb
configatron-2.5.1 lib/configatron/rails.rb
configatron-2.5.0 lib/configatron/rails.rb
configatron-2.4.2 lib/configatron/rails.rb