Class: Train::File::Local

Inherits:
Train::File show all
Defined in:
lib/train/file/local.rb,
lib/train/file/local/unix.rb,
lib/train/file/local/windows.rb

Direct Known Subclasses

Unix, Windows

Defined Under Namespace

Classes: Unix, Windows

Constant Summary

Constants inherited from Train::File

DATA_FIELDS

Instance Method Summary collapse

Methods inherited from Train::File

#directory?, #file?, #file_version, #initialize, #md5sum, #mounted?, #owned_by?, #path, #pipe?, #product_version, #sanitize_filename, #sha256sum, #socket?, #source, #source_path, #symlink?, #to_json, #version?

Constructor Details

This class inherits a constructor from Train::File

Instance Method Details

#block_device?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/train/file/local.rb', line 30

def block_device?
  ::File.blockdev?(@path)
end

#character_device?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/train/file/local.rb', line 34

def character_device?
  ::File.chardev?(@path)
end

#contentObject



14
15
16
17
18
# File 'lib/train/file/local.rb', line 14

def content
  @content ||= ::File.read(@path, encoding: 'UTF-8')
rescue StandardError => _
  nil
end


20
21
22
23
24
25
26
27
28
# File 'lib/train/file/local.rb', line 20

def link_path
  return nil unless symlink?
  begin
    @link_path ||= ::File.realpath(@path)
  rescue Errno::ELOOP => _
    # Leave it blank on symbolic loop, same as readlink
    @link_path = ''
  end
end

#linked_to?(dst) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/train/file/local.rb', line 65

def linked_to?(dst)
  link_path == dst
end

#mode?(sth) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/train/file/local.rb', line 61

def mode?(sth)
  mode == sth
end

#typeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/train/file/local.rb', line 38

def type
  case ::File.ftype(@path)
  when 'blockSpecial'
    :block_device
  when 'characterSpecial'
    :character_device
  when 'link'
    :symlink
  when 'fifo'
    :pipe
  else
    ::File.ftype(@path).to_sym
  end
end