now generates symlinked dirs in rake task, with option to turn off for specific configs
This commit is contained in:
parent
40ad20fda2
commit
b4b287f17f
@ -1 +1,6 @@
|
|||||||
Autotest.add_discovery { "rspec2" }
|
Autotest.add_discovery { "rspec2" }
|
||||||
|
|
||||||
|
Autotest.add_hook(:initialize) do |at|
|
||||||
|
at.add_exception(%r{^./test/.*})
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -93,15 +93,27 @@ module Apache
|
|||||||
config = build_and_return(&block)
|
config = build_and_return(&block)
|
||||||
|
|
||||||
FileUtils.mkdir_p File.split(target).first
|
FileUtils.mkdir_p File.split(target).first
|
||||||
File.open(target, 'w') { |file| file.puts [ "# Generated by apache-config-generator #{Time.now.to_s}", config ].flatten * "\n" }
|
File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
|
||||||
|
|
||||||
config
|
config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If included in a configuration, will not generate the symlink in the Rake task
|
||||||
|
def disable_symlink!
|
||||||
|
@is_disabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_config_file(config)
|
||||||
|
output = [ "# Generated by apache-config-generator #{Time.now.to_s}", config ]
|
||||||
|
output.unshift('# disabled') if @is_disabled
|
||||||
|
output.flatten
|
||||||
|
end
|
||||||
|
|
||||||
# Reset the current settings
|
# Reset the current settings
|
||||||
def reset!
|
def reset!
|
||||||
@config = []
|
@config = []
|
||||||
@line_indent = 0
|
@line_indent = 0
|
||||||
|
@is_disabled = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indent the string by the current @line_indent level
|
# Indent the string by the current @line_indent level
|
||||||
|
@ -16,13 +16,10 @@ namespace :apache do
|
|||||||
APACHE_ENV = (args[:environment] || get_default_environment).to_sym
|
APACHE_ENV = (args[:environment] || get_default_environment).to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
config[:source_path] = File.expand_path(config[:source])
|
|
||||||
config[:dest_path] = File.expand_path(config[:destination])
|
|
||||||
|
|
||||||
Apache::Config.rotate_logs_path = config[:rotate_logs_path]
|
Apache::Config.rotate_logs_path = config[:rotate_logs_path]
|
||||||
|
|
||||||
FileUtils.mkdir_p config[:dest_path]
|
FileUtils.mkdir_p config[:destination_path]
|
||||||
Dir.chdir config[:dest_path]
|
Dir.chdir config[:destination_path]
|
||||||
|
|
||||||
# using CONFIG is deprecated
|
# using CONFIG is deprecated
|
||||||
CONFIG = config
|
CONFIG = config
|
||||||
@ -31,6 +28,8 @@ namespace :apache do
|
|||||||
puts file.foreground(:green)
|
puts file.foreground(:green)
|
||||||
require file
|
require file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
symlink_configs!
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "List all possible environments"
|
desc "List all possible environments"
|
||||||
|
@ -5,7 +5,36 @@ module Apache
|
|||||||
module Rake
|
module Rake
|
||||||
module Support
|
module Support
|
||||||
def config
|
def config
|
||||||
@config ||= Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
|
if !@config
|
||||||
|
@config = Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
|
||||||
|
config_paths!
|
||||||
|
|
||||||
|
class << @config
|
||||||
|
def [](which)
|
||||||
|
if which == :dest_path
|
||||||
|
print "config[:dest_path] is deprecated.".foreground(:red).bright
|
||||||
|
puts " Use config[:destination_path] instead.".foreground(:red)
|
||||||
|
|
||||||
|
self[:destination_path]
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@config
|
||||||
|
end
|
||||||
|
|
||||||
|
def config_paths!
|
||||||
|
[ :source, :destination, :symlink ].each do |which|
|
||||||
|
begin
|
||||||
|
@config[:"#{which}_path"] = File.expand_path(@config[which])
|
||||||
|
rescue StandardError
|
||||||
|
puts "#{which.to_s.bright} is not defined in the configuration file.".foreground(:red)
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_environments
|
def get_environments
|
||||||
@ -37,7 +66,7 @@ module Apache
|
|||||||
FileUtils.rm_rf(config[:symlink_path])
|
FileUtils.rm_rf(config[:symlink_path])
|
||||||
FileUtils.mkdir_p(config[:symlink_path])
|
FileUtils.mkdir_p(config[:symlink_path])
|
||||||
|
|
||||||
Dir[File.join(config[:destination_path], '**/*')].each do |file|
|
Dir[File.join(config[:destination_path], '**/*')].find_all { |file| File.file?(file) }.each do |file|
|
||||||
if line = File.read(file).first
|
if line = File.read(file).first
|
||||||
if !line['# disabled']
|
if !line['# disabled']
|
||||||
target = file.gsub(config[:destination_path], config[:symlink_path])
|
target = file.gsub(config[:destination_path], config[:symlink_path])
|
||||||
|
@ -33,6 +33,32 @@ describe Apache::Config, "builds configurations" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.disable_symlink!' do
|
||||||
|
context 'is enabled by default' do
|
||||||
|
it { apache.instance_variable_get(:@is_disabled).should be_false }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'disable' do
|
||||||
|
before { apache.disable_symlink! }
|
||||||
|
|
||||||
|
it { apache.instance_variable_get(:@is_disabled).should be_true }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.generate_config_file' do
|
||||||
|
subject { apache.generate_config_file(%w{config}) }
|
||||||
|
|
||||||
|
context 'with symlink' do
|
||||||
|
its(:first) { should_not == '# disabled' }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without symlink' do
|
||||||
|
before { apache.disable_symlink! }
|
||||||
|
|
||||||
|
its(:first) { should == '# disabled' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should handle indent" do
|
it "should handle indent" do
|
||||||
apache.line_indent = 1
|
apache.line_indent = 1
|
||||||
|
|
||||||
|
@ -8,6 +8,22 @@ describe Apache::Rake::Support do
|
|||||||
let(:destination) { '/destination/available' }
|
let(:destination) { '/destination/available' }
|
||||||
let(:symlink) { '/destination/enabled' }
|
let(:symlink) { '/destination/enabled' }
|
||||||
|
|
||||||
|
describe 'config_paths!' do
|
||||||
|
before {
|
||||||
|
@config = {
|
||||||
|
:source => 'cats',
|
||||||
|
:destination => 'dogs',
|
||||||
|
:symlink => 'cows'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subject { config_paths!; @config }
|
||||||
|
|
||||||
|
its([:source_path]) { should == File.expand_path('cats') }
|
||||||
|
its([:destination_path]) { should == File.expand_path('dogs') }
|
||||||
|
its([:symlink_path]) { should == File.expand_path('cows') }
|
||||||
|
end
|
||||||
|
|
||||||
describe 'symlink_configs!' do
|
describe 'symlink_configs!' do
|
||||||
before {
|
before {
|
||||||
@config = {
|
@config = {
|
||||||
@ -45,6 +61,17 @@ describe Apache::Rake::Support do
|
|||||||
let(:filename) { File.join(destination, 'dogs/cats') }
|
let(:filename) { File.join(destination, 'dogs/cats') }
|
||||||
let(:dir_return) { [ filename ] }
|
let(:dir_return) { [ filename ] }
|
||||||
|
|
||||||
|
before { File.expects(:file?).with(filename).returns(is_file_result) }
|
||||||
|
|
||||||
|
context 'is a directory' do
|
||||||
|
let(:is_file_result) { false }
|
||||||
|
|
||||||
|
it { subject }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'is a file' do
|
||||||
|
let(:is_file_result) { true }
|
||||||
|
|
||||||
before { File.expects(:read).with(filename).returns(read_result) }
|
before { File.expects(:read).with(filename).returns(read_result) }
|
||||||
|
|
||||||
context 'config should not be symlinked' do
|
context 'config should not be symlinked' do
|
||||||
@ -68,4 +95,5 @@ describe Apache::Rake::Support do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user