class Train::Extras::FileCommon
Constants
- UNIX_MODE_OWNERS
- UNIX_MODE_TYPES
Public Class Methods
new(backend, path, follow_symlink = true)
click to toggle source
# File lib/train/extras/file_common.rb, line 21 def initialize(backend, path, follow_symlink = true) @backend = backend @path = path || '' @follow_symlink = follow_symlink end
Public Instance Methods
basename(suffix = nil, sep = '/')
click to toggle source
# File lib/train/extras/file_common.rb, line 131 def basename(suffix = nil, sep = '/') fail 'Not yet supported: Suffix in file.basename' unless suffix.nil? @basename ||= detect_filename(path, sep || '/') end
block_device?()
click to toggle source
# File lib/train/extras/file_common.rb, line 56 def block_device? type == :block_device end
character_device?()
click to toggle source
# File lib/train/extras/file_common.rb, line 60 def character_device? type == :character_device end
directory?()
click to toggle source
# File lib/train/extras/file_common.rb, line 68 def directory? type == :directory end
file?()
click to toggle source
Additional methods for convenience
# File lib/train/extras/file_common.rb, line 52 def file? type == :file end
grouped_into?(sth)
click to toggle source
# File lib/train/extras/file_common.rb, line 100 def grouped_into?(sth) group == sth end
link_path()
click to toggle source
# File lib/train/extras/file_common.rb, line 108 def link_path symlink? ? path : nil end
linked_to?(dst)
click to toggle source
# File lib/train/extras/file_common.rb, line 104 def linked_to?(dst) link_path == dst end
md5sum()
click to toggle source
The following methods can be overwritten by a derived class if desired, to e.g. achieve optimizations.
# File lib/train/extras/file_common.rb, line 34 def md5sum res = Digest::MD5.new res.update(content) res.hexdigest rescue TypeError => _ nil end
mode?(sth)
click to toggle source
# File lib/train/extras/file_common.rb, line 92 def mode?(sth) mode == sth end
mounted?()
click to toggle source
# File lib/train/extras/file_common.rb, line 127 def mounted? !mounted.nil? && !mounted.stdout.nil? && !mounted.stdout.empty? end
owned_by?(sth)
click to toggle source
# File lib/train/extras/file_common.rb, line 96 def owned_by?(sth) owner == sth end
pipe?()
click to toggle source
# File lib/train/extras/file_common.rb, line 88 def pipe? type == :pipe end
sha256sum()
click to toggle source
# File lib/train/extras/file_common.rb, line 42 def sha256sum res = Digest::SHA256.new res.update(content) res.hexdigest rescue TypeError => _ nil end
socket?()
click to toggle source
# File lib/train/extras/file_common.rb, line 64 def socket? type == :socket end
source()
click to toggle source
# File lib/train/extras/file_common.rb, line 80 def source if @follow_symlink self.class.new(@backend, @path, false) else self end end
source_path()
click to toggle source
# File lib/train/extras/file_common.rb, line 76 def source_path @path end
symlink?()
click to toggle source
# File lib/train/extras/file_common.rb, line 72 def symlink? source.type == :symlink end
type()
click to toggle source
# File lib/train/extras/file_common.rb, line 27 def type :unknown end
unix_mode_mask(owner, type)
click to toggle source
# File lib/train/extras/file_common.rb, line 117 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)
click to toggle source
# File lib/train/extras/file_common.rb, line 112 def version?(version) product_version == version or file_version == version end
Private Instance Methods
detect_filename(path, sep)
click to toggle source
helper methods provided to any implementing class
# File lib/train/extras/file_common.rb, line 140 def detect_filename(path, sep) idx = path.rindex(sep) return path if idx.nil? idx += 1 return detect_filename(path[0..-2], sep) if idx == path.length path[idx..-1] end