a bunch of updates, especially to the rake apache:create task
This commit is contained in:
parent
0926ca1887
commit
d373738451
@ -1,17 +1,29 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'fileutils'
|
||||
require 'rubygems'
|
||||
require 'rainbow'
|
||||
|
||||
if !ARGV[0]
|
||||
puts "Directory name required."
|
||||
puts "Directory name required.".foreground(:red)
|
||||
exit 1
|
||||
end
|
||||
|
||||
if File.directory?(ARGV[0])
|
||||
puts "You can't overwrite an existing directory."
|
||||
puts "You can't overwrite an existing directory.".foreground(:red)
|
||||
exit 1
|
||||
end
|
||||
|
||||
puts "Copying skel files...".foreground(:green)
|
||||
FileUtils.cp_r File.expand_path(File.join(File.dirname(__FILE__), '..', 'skel')), ARGV[0]
|
||||
|
||||
puts "Making config directories...".foreground(:green)
|
||||
FileUtils.mkdir_p File.join(ARGV[0], 'source')
|
||||
FileUtils.mkdir_p File.join(ARGV[0], 'conf.d-original')
|
||||
FileUtils.mkdir_p File.join(ARGV[0], 'conf.d')
|
||||
|
||||
print "Complete! ".bright.foreground(:green)
|
||||
print "cd #{ARGV[0]}".bright.foreground(:yellow)
|
||||
print " and run ".foreground(:green)
|
||||
print "bundle exec rake -T ".bright.foreground(:yellow)
|
||||
puts "to get started.".foreground(:green)
|
||||
|
@ -94,6 +94,7 @@ module Apache
|
||||
|
||||
FileUtils.mkdir_p File.split(target).first
|
||||
File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
|
||||
@was_written = true
|
||||
|
||||
config
|
||||
end
|
||||
@ -103,6 +104,14 @@ module Apache
|
||||
@is_disabled = true
|
||||
end
|
||||
|
||||
def disabled?
|
||||
@is_disabled
|
||||
end
|
||||
|
||||
def written?
|
||||
@was_written
|
||||
end
|
||||
|
||||
def generate_config_file(config)
|
||||
output = [ "# Generated by apache-config-generator #{Time.now.to_s}", config ]
|
||||
output.unshift('# disabled') if @is_disabled
|
||||
@ -114,6 +123,7 @@ module Apache
|
||||
@config = []
|
||||
@line_indent = 0
|
||||
@is_disabled = false
|
||||
@was_written = false
|
||||
end
|
||||
|
||||
# Indent the string by the current @line_indent level
|
||||
|
8
lib/apache/hash.rb
Normal file
8
lib/apache/hash.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class Hash
|
||||
def to_sym_keys
|
||||
Hash[self.collect { |key, value|
|
||||
value = value.to_sym_keys if value.kind_of?(Hash)
|
||||
[ key.to_sym, value ]
|
||||
}]
|
||||
end
|
||||
end
|
@ -5,6 +5,15 @@ 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|
|
||||
@ -21,12 +30,22 @@ namespace :apache do
|
||||
FileUtils.mkdir_p config[:destination_path]
|
||||
Dir.chdir config[:destination_path]
|
||||
|
||||
# using CONFIG is deprecated
|
||||
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)
|
||||
require file
|
||||
end
|
||||
puts output
|
||||
end
|
||||
end
|
||||
|
||||
symlink_configs!
|
||||
|
@ -1,12 +1,13 @@
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require 'apache/hash'
|
||||
|
||||
module Apache
|
||||
module Rake
|
||||
module Support
|
||||
def config
|
||||
if !@config
|
||||
@config = Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
|
||||
@config = YAML.load_file('config.yml').to_sym_keys
|
||||
config_paths!
|
||||
|
||||
class << @config
|
||||
|
5
skel/Gemfile
Normal file
5
skel/Gemfile
Normal file
@ -0,0 +1,5 @@
|
||||
source :rubygems
|
||||
|
||||
gem 'apache-config-generator', '>= 0.2.7'
|
||||
gem 'rake'
|
||||
|
@ -1,4 +1 @@
|
||||
require 'rubygems'
|
||||
|
||||
require 'apache-config-generator'
|
||||
require 'apache/rake/create'
|
||||
require 'apache/rake/apache/create'
|
||||
|
@ -36,12 +36,14 @@ describe Apache::Config, "builds configurations" do
|
||||
describe '.disable_symlink!' do
|
||||
context 'is enabled by default' do
|
||||
it { apache.instance_variable_get(:@is_disabled).should be_false }
|
||||
it { apache.disabled?.should be_false }
|
||||
end
|
||||
|
||||
context 'disable' do
|
||||
before { apache.disable_symlink! }
|
||||
|
||||
it { apache.instance_variable_get(:@is_disabled).should be_true }
|
||||
it { apache.disabled?.should be_true }
|
||||
end
|
||||
end
|
||||
|
||||
@ -110,9 +112,13 @@ describe Apache::Config, "builds configurations" do
|
||||
end
|
||||
|
||||
it "should handle a build" do
|
||||
apache.written?.should be_false
|
||||
|
||||
FileUtils.mkdir_p 'test'
|
||||
apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
|
||||
FileUtils.rm 'test/fake.conf'
|
||||
|
||||
apache.written?.should be_true
|
||||
end
|
||||
|
||||
it "should handle building if the environment is correct" do
|
||||
|
36
spec/apache/hash_spec.rb
Normal file
36
spec/apache/hash_spec.rb
Normal file
@ -0,0 +1,36 @@
|
||||
require 'spec_helper'
|
||||
require 'lib/apache/hash'
|
||||
|
||||
describe Hash do
|
||||
describe '#to_sym_keys' do
|
||||
subject { test_hash.to_sym_keys }
|
||||
|
||||
context 'no nested hashes' do
|
||||
let(:test_hash) { {
|
||||
'hello' => 'goodbye',
|
||||
:other => 'this'
|
||||
} }
|
||||
|
||||
it { should == {
|
||||
:hello => 'goodbye',
|
||||
:other => 'this'
|
||||
} }
|
||||
end
|
||||
|
||||
context 'nested hash' do
|
||||
let(:test_hash) { {
|
||||
'hello' => 'goodbye',
|
||||
:other => {
|
||||
'this' => 'that'
|
||||
}
|
||||
} }
|
||||
|
||||
it { should == {
|
||||
:hello => 'goodbye',
|
||||
:other => {
|
||||
:this => 'that'
|
||||
}
|
||||
} }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user