4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/capfig.rb', line 4
def configuration_for(name, settings = {})
settings[:path], settings[:filename] = File.split(settings[:filepath]) if settings[:filepath]
settings[:path] ||= 'config'
settings[:chmod] ||= 775
after 'deploy:update_code', "#{name}:symlink"
before 'deploy:setup', name.to_sym
namespace(name.to_sym) do
desc "Configuration for #{name}"
task(:default) do
set(:shared_dir) { File.join(fetch(:shared_path), settings[:path]) }
set(:shared_file) { File.join(fetch(:shared_dir), settings[:filename]) } if settings[:filename]
run "mkdir -p #{shared_dir}"
run "chmod #{settings[:chmod]} #{shared_dir}" if settings[:chmod]
if settings[:filename]
settings[:text] = yield if block_given?
puts settings[:text], shared_file
run "chmod #{settings[:chmod]} #{shared_file}"
elsif block_given?
yield
end
end
sym_path = File.join(File.split("#{settings[:path]}/#{settings[:filename]}"))
symlink_task name, sym_path, :chmod => settings[:chmod]
end
end
|