Class: Train::Extras::FileCommon

Inherits:
Object
  • Object
show all
Defined in:
lib/train/extras/file_common.rb

Direct Known Subclasses

LinuxFile, WindowsFile

Instance Method Summary collapse

Instance Method Details

#block_device?Boolean

Returns:

  • (Boolean)


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

def block_device?
  target_type == :block_device
end

#character_device?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/train/extras/file_common.rb', line 54

def character_device?
  target_type == :character_device
end

#directory?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/train/extras/file_common.rb', line 62

def directory?
  target_type == :directory
end

#file?Boolean

Additional methods for convenience

Returns:

  • (Boolean)


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

def file?
  target_type == :file
end

#grouped_into?(sth) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/train/extras/file_common.rb', line 82

def grouped_into?(sth)
  group == sth
end

#linked_to?(dst) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/train/extras/file_common.rb', line 86

def linked_to?(dst)
  link_path == dst
end

#md5sumObject

The following methods can be overwritten by a derived class if desired, to e.g. achieve optimizations.



28
29
30
31
32
33
34
# File 'lib/train/extras/file_common.rb', line 28

def md5sum
  res = Digest::MD5.new
  res.update(content)
  res.hexdigest
rescue TypeError => _
  nil
end

#mode?(sth) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/train/extras/file_common.rb', line 74

def mode?(sth)
  mode == sth
end

#mounted?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/train/extras/file_common.rb', line 105

def mounted?
  !mounted.nil? && !mounted.stdout.nil? && !mounted.stdout.empty?
end

#owned_by?(sth) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/train/extras/file_common.rb', line 78

def owned_by?(sth)
  owner == sth
end

#pipe?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/train/extras/file_common.rb', line 70

def pipe?
  target_type == :pipe
end

#sha256sumObject



36
37
38
39
40
41
42
# File 'lib/train/extras/file_common.rb', line 36

def sha256sum
  res = Digest::SHA256.new
  res.update(content)
  res.hexdigest
rescue TypeError => _
  nil
end

#socket?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/train/extras/file_common.rb', line 58

def socket?
  target_type == :socket
end

#symlink?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/train/extras/file_common.rb', line 66

def symlink?
  type == :symlink
end

#typeObject



21
22
23
# File 'lib/train/extras/file_common.rb', line 21

def type
  :unknown
end

#unix_mode_mask(owner, type) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/train/extras/file_common.rb', line 95

def unix_mode_mask(owner, type)
  o = UNIX_MODE_OWNERS[owner.to_sym]
  return nil if o.nil?

  t = UNIX_MODE_TYPES[type.to_sym]
  return nil if t.nil?

  t & o
end

#version?(version) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
# File 'lib/train/extras/file_common.rb', line 90

def version?(version)
  product_version == version or
    file_version == version
end