Class: Train::Extras::FileCommon
- Inherits:
-
Object
- Object
- Train::Extras::FileCommon
- Defined in:
- lib/train/extras/file_common.rb
Overview
rubocop:disable Metrics/ClassLength
Direct Known Subclasses
Instance Method Summary collapse
- #basename(suffix = nil, sep = '/') ⇒ Object
- #block_device? ⇒ Boolean
- #character_device? ⇒ Boolean
- #directory? ⇒ Boolean
-
#file? ⇒ Boolean
Additional methods for convenience.
- #grouped_into?(sth) ⇒ Boolean
-
#initialize(backend, path, follow_symlink = true) ⇒ FileCommon
constructor
A new instance of FileCommon.
- #link_path ⇒ Object
- #linked_to?(dst) ⇒ Boolean
-
#md5sum ⇒ Object
The following methods can be overwritten by a derived class if desired, to e.g.
- #mode?(sth) ⇒ Boolean
- #mounted? ⇒ Boolean
- #owned_by?(sth) ⇒ Boolean
- #pipe? ⇒ Boolean
- #sha256sum ⇒ Object
- #socket? ⇒ Boolean
- #source ⇒ Object
- #source_path ⇒ Object
- #symlink? ⇒ Boolean
- #type ⇒ Object
- #unix_mode_mask(owner, type) ⇒ Object
- #version?(version) ⇒ Boolean
Constructor Details
#initialize(backend, path, follow_symlink = true) ⇒ FileCommon
Returns a new instance of FileCommon.
21 22 23 24 25 |
# 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 |
Instance Method Details
#basename(suffix = nil, sep = '/') ⇒ Object
131 132 133 134 |
# 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? ⇒ Boolean
56 57 58 |
# File 'lib/train/extras/file_common.rb', line 56 def block_device? type == :block_device end |
#character_device? ⇒ Boolean
60 61 62 |
# File 'lib/train/extras/file_common.rb', line 60 def character_device? type == :character_device end |
#directory? ⇒ Boolean
68 69 70 |
# File 'lib/train/extras/file_common.rb', line 68 def directory? type == :directory end |
#file? ⇒ Boolean
Additional methods for convenience
52 53 54 |
# File 'lib/train/extras/file_common.rb', line 52 def file? type == :file end |
#grouped_into?(sth) ⇒ Boolean
100 101 102 |
# File 'lib/train/extras/file_common.rb', line 100 def grouped_into?(sth) group == sth end |
#link_path ⇒ Object
108 109 110 |
# File 'lib/train/extras/file_common.rb', line 108 def link_path symlink? ? path : nil end |
#linked_to?(dst) ⇒ Boolean
104 105 106 |
# File 'lib/train/extras/file_common.rb', line 104 def linked_to?(dst) link_path == dst end |
#md5sum ⇒ Object
The following methods can be overwritten by a derived class if desired, to e.g. achieve optimizations.
34 35 36 37 38 39 40 |
# 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) ⇒ Boolean
92 93 94 |
# File 'lib/train/extras/file_common.rb', line 92 def mode?(sth) mode == sth end |
#mounted? ⇒ Boolean
127 128 129 |
# File 'lib/train/extras/file_common.rb', line 127 def mounted? !mounted.nil? && !mounted.stdout.nil? && !mounted.stdout.empty? end |
#owned_by?(sth) ⇒ Boolean
96 97 98 |
# File 'lib/train/extras/file_common.rb', line 96 def owned_by?(sth) owner == sth end |
#pipe? ⇒ Boolean
88 89 90 |
# File 'lib/train/extras/file_common.rb', line 88 def pipe? type == :pipe end |
#sha256sum ⇒ Object
42 43 44 45 46 47 48 |
# 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? ⇒ Boolean
64 65 66 |
# File 'lib/train/extras/file_common.rb', line 64 def socket? type == :socket end |
#source ⇒ Object
80 81 82 83 84 85 86 |
# 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 ⇒ Object
76 77 78 |
# File 'lib/train/extras/file_common.rb', line 76 def source_path @path end |
#symlink? ⇒ Boolean
72 73 74 |
# File 'lib/train/extras/file_common.rb', line 72 def symlink? source.type == :symlink end |
#type ⇒ Object
27 28 29 |
# File 'lib/train/extras/file_common.rb', line 27 def type :unknown end |
#unix_mode_mask(owner, type) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Boolean
112 113 114 115 |
# File 'lib/train/extras/file_common.rb', line 112 def version?(version) product_version == version or file_version == version end |