Module: PSWindows::File
Instance Attribute Summary
Attributes included from Beaker::CommandFactory
Instance Method Summary collapse
- #cat(path) ⇒ Object
- #file_exist?(path) ⇒ Boolean
- #path_split(paths) ⇒ Object
- #tmpdir(name = '') ⇒ Object
- #tmpfile(name = '', extension = nil) ⇒ Object
Methods included from Beaker::CommandFactory
Instance Method Details
#cat(path) ⇒ Object
38 39 40 |
# File 'lib/beaker/host/pswindows/file.rb', line 38 def cat(path) exec(powershell("type #{path}")).stdout end |
#file_exist?(path) ⇒ Boolean
42 43 44 45 |
# File 'lib/beaker/host/pswindows/file.rb', line 42 def file_exist?(path) result = exec(Beaker::Command.new("if exist #{path} echo true"), accept_all_exit_codes: true) result.stdout.strip == 'true' end |
#path_split(paths) ⇒ Object
34 35 36 |
# File 'lib/beaker/host/pswindows/file.rb', line 34 def path_split(paths) paths.split(';') end |
#tmpdir(name = '') ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/beaker/host/pswindows/file.rb', line 26 def tmpdir(name = '') tmp_path = exec(powershell('[System.IO.Path]::GetTempPath()')).stdout.chomp name = exec(powershell('[System.IO.Path]::GetRandomFileName()')).stdout.chomp if name == '' exec(powershell("New-Item -Path '#{tmp_path}' -Force -Name '#{name}' -ItemType 'directory'")) File.join(tmp_path, name) end |
#tmpfile(name = '', extension = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/beaker/host/pswindows/file.rb', line 4 def tmpfile(name = '', extension = nil) tmp_path = exec(powershell('[System.IO.Path]::GetTempPath()')).stdout.chomp if name.empty? base_name = exec(powershell('[System.IO.Path]::GetRandomFileName()')).stdout.chomp else base_name = name end if extension # Remove existing extension if present and add the new one base_name = base_name.sub(/\.[^.]+$/, '') final_name = "#{base_name}.#{extension}" else final_name = base_name end file_path = File.join(tmp_path, final_name) exec(powershell("New-Item -Path '#{file_path}' -ItemType 'file' -Force")) file_path end |