diff --git a/lib/apache/rake/apache/symlink.rb b/lib/apache/rake/apache/symlink.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/apache/rake/support.rb b/lib/apache/rake/support.rb index 6b5138a..b846221 100644 --- a/lib/apache/rake/support.rb +++ b/lib/apache/rake/support.rb @@ -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 diff --git a/spec/apache/rake/support_spec.rb b/spec/apache/rake/support_spec.rb new file mode 100644 index 0000000..d80f9a7 --- /dev/null +++ b/spec/apache/rake/support_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69de29..b9a1fd4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +Rspec.configure do |config| + config.mock_with :mocha +end