Sha256: 25300c5f19819fbcac5bf37a1cb1d2d50753d0a3955d34d30922fcff2ad409ab

Contents?: true

Size: 1.53 KB

Versions: 17

Compression:

Stored size: 1.53 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) ? ::Rails.root : FileUtils.pwd
        base_dir = File.expand_path(File.join(root, 'config', 'configatron'))
      end
      
      if env.nil?
        env = defined?(Rails) ? ::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

17 entries across 17 versions & 1 rubygems

Version Path
configatron-2.13.0 lib/configatron/rails.rb
configatron-2.12.0 lib/configatron/rails.rb
configatron-2.11.0 lib/configatron/rails.rb
configatron-2.10.0 lib/configatron/rails.rb
configatron-2.9.1 lib/configatron/rails.rb
configatron-2.9.0 lib/configatron/rails.rb
configatron-2.8.4 lib/configatron/rails.rb
configatron-2.8.3 lib/configatron/rails.rb
configatron-2.8.2 lib/configatron/rails.rb
configatron-2.8.1 lib/configatron/rails.rb
configatron-2.8.0 lib/configatron/rails.rb
configatron-2.7.2 lib/configatron/rails.rb
configatron-2.7.1 lib/configatron/rails.rb
configatron-2.7.0 lib/configatron/rails.rb
configatron-2.6.4 lib/configatron/rails.rb
configatron-2.6.3 lib/configatron/rails.rb
configatron-2.6.2 lib/configatron/rails.rb