start work on symlink dir generation
This commit is contained in:
parent
d68388a578
commit
40ad20fda2
0
lib/apache/rake/apache/symlink.rb
Normal file
0
lib/apache/rake/apache/symlink.rb
Normal file
@ -30,6 +30,23 @@ module Apache
|
||||
puts "rake apache:default[#{get_environments.first}]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
def symlink_configs!
|
||||
raise Errno::ENOENT if !File.directory?(config[:destination_path])
|
||||
|
||||
FileUtils.rm_rf(config[:symlink_path])
|
||||
FileUtils.mkdir_p(config[:symlink_path])
|
||||
|
||||
Dir[File.join(config[:destination_path], '**/*')].each do |file|
|
||||
if line = File.read(file).first
|
||||
if !line['# disabled']
|
||||
target = file.gsub(config[:destination_path], config[:symlink_path])
|
||||
FileUtils.mkdir_p(File.split(target).first)
|
||||
FileUtils.ln_sf(file, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
71
spec/apache/rake/support_spec.rb
Normal file
71
spec/apache/rake/support_spec.rb
Normal file
@ -0,0 +1,71 @@
|
||||
require 'spec_helper'
|
||||
require 'apache/rake/support'
|
||||
|
||||
describe Apache::Rake::Support do
|
||||
include Apache::Rake::Support
|
||||
|
||||
let(:source) { '/source' }
|
||||
let(:destination) { '/destination/available' }
|
||||
let(:symlink) { '/destination/enabled' }
|
||||
|
||||
describe 'symlink_configs!' do
|
||||
before {
|
||||
@config = {
|
||||
:source_path => source,
|
||||
:destination_path => destination,
|
||||
:symlink_path => symlink
|
||||
}
|
||||
}
|
||||
|
||||
subject { symlink_configs! }
|
||||
|
||||
context 'source does not exist' do
|
||||
before { File.expects(:directory?).with(destination).returns(false) }
|
||||
|
||||
it { expect { subject }.to raise_error(Errno::ENOENT) }
|
||||
end
|
||||
|
||||
context 'source does exist' do
|
||||
before {
|
||||
File.expects(:directory?).with(destination).returns(true)
|
||||
FileUtils.expects(:rm_rf).with(symlink)
|
||||
FileUtils.expects(:mkdir_p).with(symlink)
|
||||
Dir.expects(:[]).with(File.join(destination, '**/*')).returns(dir_return)
|
||||
}
|
||||
|
||||
context 'with no configs' do
|
||||
let(:dir_return) { [] }
|
||||
|
||||
before { FileUtils.expects(:ln_sf).never }
|
||||
|
||||
it { subject }
|
||||
end
|
||||
|
||||
context 'with one config' do
|
||||
let(:filename) { File.join(destination, 'dogs/cats') }
|
||||
let(:dir_return) { [ filename ] }
|
||||
|
||||
before { File.expects(:read).with(filename).returns(read_result) }
|
||||
|
||||
context 'config should not be symlinked' do
|
||||
let(:read_result) { ['# disabled'] }
|
||||
|
||||
before { FileUtils.expects(:ln_sf).never }
|
||||
|
||||
it { subject }
|
||||
end
|
||||
|
||||
context 'config should be symlinked' do
|
||||
let(:read_result) { ['# whatever'] }
|
||||
|
||||
before {
|
||||
FileUtils.expects(:mkdir_p).with(File.join(symlink, 'dogs'))
|
||||
FileUtils.expects(:ln_sf).with(filename, filename.gsub(destination, symlink))
|
||||
}
|
||||
|
||||
it { subject }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
Rspec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
Loading…
Reference in New Issue
Block a user