Module: Flak::FileActions
- Included in:
- Target
- Defined in:
- lib/flak/rake/file_actions.rb
Instance Method Summary collapse
-
#make_directory_for(file) ⇒ Object
Make a directory to contain a file.
-
#rebuild_symlink(target_file, new_file) ⇒ Object
Create a symlink.
-
#remove_and_copy(source, destination) ⇒ Object
Remove a file and copy a new file over.
-
#write_erb_template(erb_file, released_file, opts = {}) ⇒ Object
Create a destination file by filtering a source file through ERB.
Instance Method Details
#make_directory_for(file) ⇒ Object
Make a directory to contain a file. Create directories recursively if necessary.
43 44 45 |
# File 'lib/flak/rake/file_actions.rb', line 43 def make_directory_for(file) FileUtils.mkdir_p file.pathmap('%d') end |
#rebuild_symlink(target_file, new_file) ⇒ Object
Create a symlink. Remove it if it already exists.
16 17 18 19 20 21 |
# File 'lib/flak/rake/file_actions.rb', line 16 def rebuild_symlink(target_file,new_file) if File.symlink?(new_file) File.unlink(new_file) end File.symlink(target_file, new_file) end |
#remove_and_copy(source, destination) ⇒ Object
Remove a file and copy a new file over. If we just copy source to destination and destination exists and is a directory, then the src is put in the destination, as opposed to overwriting it. For this reason, we delete destination first.
32 33 34 35 |
# File 'lib/flak/rake/file_actions.rb', line 32 def remove_and_copy(source,destination) remove_file(destination, true) cp_r source, destination end |
#write_erb_template(erb_file, released_file, opts = {}) ⇒ Object
Create a destination file by filtering a source file through ERB.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/flak/rake/file_actions.rb', line 54 def write_erb_template(erb_file,released_file, opts={}) if (!(opts[:no_force] && File.exists?(released_file) )) template = ERB.new( File.read(erb_file) , 0, "%<>") File.open(released_file, 'w') do |f| puts "template #{erb_file} #{released_file}" f.puts(template.result(binding)) f.chmod(opts[:chmod].to_i) if opts[:chmod] end end end |