Module: FileHelpers
- Defined in:
- lib/SimpliTest/helpers/file.rb
Instance Method Summary collapse
- #copy_file(source, target) ⇒ Object
- #copy_file_with_replacement_args(template_name, target_location, args = {}) ⇒ Object
- #copy_folder(source, target) ⇒ Object
- #make_directory(dirname) ⇒ Object
- #make_subdirectories_in(directory, *subdirectories) ⇒ Object
- #template_path_to(*args) ⇒ Object
Instance Method Details
#copy_file(source, target) ⇒ Object
8 9 10 |
# File 'lib/SimpliTest/helpers/file.rb', line 8 def copy_file(source, target) FileUtils.cp(source, target) end |
#copy_file_with_replacement_args(template_name, target_location, args = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/SimpliTest/helpers/file.rb', line 27 def copy_file_with_replacement_args(template_name, target_location, args={}) file = File.open(template_path_to(template_name)) content = file.read target_location = File.join(@pwd, template_name) unless target_location args.each do |key, value| content = content.gsub(/#{key}/,value ) end File.open(target_location, 'w') { |f| f.write(content) } end |
#copy_folder(source, target) ⇒ Object
12 13 14 |
# File 'lib/SimpliTest/helpers/file.rb', line 12 def copy_folder(source, target) FileUtils.copy_entry(source, target) end |
#make_directory(dirname) ⇒ Object
4 5 6 |
# File 'lib/SimpliTest/helpers/file.rb', line 4 def make_directory(dirname) FileUtils.mkdir_p(dirname) end |
#make_subdirectories_in(directory, *subdirectories) ⇒ Object
16 17 18 19 20 |
# File 'lib/SimpliTest/helpers/file.rb', line 16 def make_subdirectories_in(directory, *subdirectories) subdirectories.each do |subdir| FileUtils.mkdir_p(File.join(directory, subdir)) end end |
#template_path_to(*args) ⇒ Object
22 23 24 25 |
# File 'lib/SimpliTest/helpers/file.rb', line 22 def template_path_to(*args) relative_path = args.join(File::Separator) File.join(SimpliTest.path_to_templates_dir, relative_path) end |