Sha256: 2ebd521fb7ce9b62714b0d7e40ad1cf73e18b93978a2d5d5b20a73a0ef076573

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

class Configatron::Integrations
  # Helpful for making using configatron with Rails even easier!
  #
  # To get started you can use the generator to generate
  # the necessary stub files.
  #
  #   $ rails g configatron:install
  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

4 entries across 4 versions & 1 rubygems

Version Path
configatron-4.0.3 lib/configatron/integrations/rails.rb
configatron-4.0.2 lib/configatron/integrations/rails.rb
configatron-4.0.1 lib/configatron/integrations/rails.rb
configatron-4.0.0 lib/configatron/integrations/rails.rb