class Train::Extras::WindowsFile
Attributes
path[R]
Public Class Methods
new(backend, path, follow_symlink = false)
click to toggle source
Calls superclass method
Train::Extras::FileCommon::new
# 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
Public Instance Methods
basename(suffix = nil, sep = '\\')
click to toggle source
Calls superclass method
Train::Extras::FileCommon#basename
# File lib/train/extras/file_windows.rb, line 19 def basename(suffix = nil, sep = '\\') super(suffix, sep) end
content()
click to toggle source
# 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? # or size.nil? or size > 0 @content end
exist?()
click to toggle source
# 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()
click to toggle source
# File lib/train/extras/file_windows.rb, line 75 def file_version nil end
link_path()
click to toggle source
# File lib/train/extras/file_windows.rb, line 46 def link_path nil end
mounted()
click to toggle source
# File lib/train/extras/file_windows.rb, line 50 def mounted nil end
product_version()
click to toggle source
# File lib/train/extras/file_windows.rb, line 71 def product_version nil end
sanitize_filename(filename)
click to toggle source
Ensures we do not use invalid characters for file names @see msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
# File lib/train/extras/file_windows.rb, line 25 def sanitize_filename(filename) return if filename.nil? # we do not filter :, backslash and forward slash, since they are part of the path filename.gsub(/[<>"|?*]/, '') end
stat()
click to toggle source
# File lib/train/extras/file_windows.rb, line 79 def stat nil end
type()
click to toggle source
# 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
Private Instance Methods
attributes()
click to toggle source
# File lib/train/extras/file_windows.rb, line 85 def attributes return @attributes if defined?(@attributes) @attributes = @backend.run_command( "(Get-ItemProperty -Path \"#{@spath}\").attributes.ToString()").stdout.chomp.split(/\s*,\s*/) end