Sha256: 4c0ab1b51da45ad30f8b131ee85da39a48598bc1ae8b092fb2b52dc0a2f6347e

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'apache/config'
require 'apache/rake/support'

include Apache::Rake::Support

task :default => 'apache:create'

def capture_stdout
  buffer = StringIO.new
  $stdout = buffer
  yield
  $stdout = STDOUT
  buffer.rewind
  buffer.read
end

namespace :apache do
  desc "Create all defined configs for the specified environment"
  task :create, :environment do |t, args|
    if get_environments.empty?
      APACHE_ENV = true
    else
      need_environment if !args[:environment] && !get_default_environment

      APACHE_ENV = (args[:environment] || get_default_environment).to_sym
    end

    Apache::Config.rotate_logs_path = config[:rotate_logs_path]

    FileUtils.rm_rf config[:destination_path]
    FileUtils.mkdir_p config[:destination_path]
    Dir.chdir config[:destination_path]

    CONFIG = config

    ENVIRONMENT_CONFIG = (config[:environments][APACHE_ENV] rescue nil)

    Dir[File.join(config[:source_path], '**', '*.rb')].each do |file|
      Apache::Config.reset!
      output = capture_stdout { require file }

      if Apache::Config.written?
        if Apache::Config.disabled?
          puts file.foreground(:blue)
        else
          puts file.foreground(:green)
        end
        puts output
      end
    end
  end

  desc "List all possible environments"
  task :environments do
    puts get_environments * "\n"
  end

  desc "Set the default environment (currently #{get_default_environment || 'nil'})"
  task :default, :environment do |t, args|
    need_environment if !args[:environment]

    if get_environments.include?(args[:environment])
      File.open('.environment', 'w') { |fh| fh.puts args[:environment] }
      puts "Calls to apache:create will now use #{args[:environment]} when you don't specify the environment."
    else
      puts "You need to specify a valid default environment. Here are the possibilities:"
      Rake::Task['apache:environments'].invoke
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apache-config-generator-0.2.7 lib/apache/rake/apache/create.rb