Class: Train::Extras::WindowsFile

Inherits:
FileCommon show all
Defined in:
lib/train/extras/file_windows.rb

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?, #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

#pathObject (readonly)

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

#contentObject



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? # or size.nil? or size > 0
  @content
end

#exist?Boolean

Returns:

  • (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_versionObject



75
76
77
# File 'lib/train/extras/file_windows.rb', line 75

def file_version
  nil
end


46
47
48
# File 'lib/train/extras/file_windows.rb', line 46

def link_path
  nil
end

#mountedObject



50
51
52
# File 'lib/train/extras/file_windows.rb', line 50

def mounted
  nil
end

#product_versionObject



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?
  # we do not filter :, backslash and forward slash, since they are part of the path
  filename.gsub(/[<>"|?*]/, '')
end

#statObject



79
80
81
# File 'lib/train/extras/file_windows.rb', line 79

def stat
  nil
end

#typeObject



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