Class: Train::Extras::WindowsFile
Constant Summary
Constants inherited
from FileCommon
FileCommon::DATA_FIELDS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from FileCommon
#block_device?, #character_device?, #directory?, #file?, #grouped_into?, #linked_to?, #md5sum, #mode?, #mounted?, #owned_by?, #pipe?, #sha256sum, #socket?, #source, #source_path, #symlink?, #to_json, #unix_mode_mask, #version?
Constructor Details
#initialize(backend, path, follow_symlink = false) ⇒ WindowsFile
Returns a new instance of WindowsFile.
14
15
16
17
|
# File 'lib/train/extras/file_windows.rb', line 14
def initialize(backend, path, follow_symlink = false)
super(backend, path, follow_symlink)
@spath = sanitize_filename(@path)
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
13
14
15
|
# File 'lib/train/extras/file_windows.rb', line 13
def path
@path
end
|
Instance Method Details
#basename(suffix = nil, sep = '\\') ⇒ Object
19
20
21
|
# File 'lib/train/extras/file_windows.rb', line 19
def basename(suffix = nil, sep = '\\')
super(suffix, sep)
end
|
#content ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/train/extras/file_windows.rb', line 31
def content
return @content if defined?(@content)
@content = @backend.run_command(
"Get-Content(\"#{@spath}\") | Out-String").stdout
return @content unless @content.empty?
@content = nil if directory? @content
end
|
#exist? ⇒ Boolean
40
41
42
43
44
|
# File 'lib/train/extras/file_windows.rb', line 40
def exist?
return @exist if defined?(@exist)
@exist = @backend.run_command(
"(Test-Path -Path \"#{@spath}\").ToString()").stdout.chomp == 'True'
end
|
#file_version ⇒ Object
75
76
77
|
# File 'lib/train/extras/file_windows.rb', line 75
def file_version
nil
end
|
#link_path ⇒ Object
46
47
48
|
# File 'lib/train/extras/file_windows.rb', line 46
def link_path
nil
end
|
#mounted ⇒ Object
50
51
52
|
# File 'lib/train/extras/file_windows.rb', line 50
def mounted
nil
end
|
#product_version ⇒ Object
71
72
73
|
# File 'lib/train/extras/file_windows.rb', line 71
def product_version
nil
end
|
#sanitize_filename(filename) ⇒ Object
Ensures we do not use invalid characters for file names
25
26
27
28
29
|
# File 'lib/train/extras/file_windows.rb', line 25
def sanitize_filename(filename)
return if filename.nil?
filename.gsub(/[<>"|?*]/, '')
end
|
#stat ⇒ Object
79
80
81
|
# File 'lib/train/extras/file_windows.rb', line 79
def stat
nil
end
|
#type ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/train/extras/file_windows.rb', line 54
def type
if attributes.include?('Archive')
return :file
elsif attributes.include?('Directory')
return :directory
end
:unknown
end
|