Class: Train::Extras::UnixFile
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from FileCommon
#basename, #block_device?, #character_device?, #directory?, #file?, #grouped_into?, #linked_to?, #md5sum, #mode?, #mounted?, #owned_by?, #pipe?, #sha256sum, #socket?, #symlink?, #type, #unix_mode_mask, #version?
Constructor Details
#initialize(backend, path) ⇒ UnixFile
Returns a new instance of UnixFile.
11
12
13
14
15
|
# File 'lib/train/extras/file_unix.rb', line 11
def initialize(backend, path)
@backend = backend
@path = path
@spath = Shellwords.escape(@path)
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
10
11
12
|
# File 'lib/train/extras/file_unix.rb', line 10
def path
@path
end
|
Instance Method Details
#content ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/train/extras/file_unix.rb', line 17
def content
@content ||= case
when !exist?, directory?
nil
when size.nil?, size == 0
''
else
@backend.run_command("cat #{@spath}").stdout || ''
end
end
|
#exist? ⇒ Boolean
28
29
30
31
32
33
|
# File 'lib/train/extras/file_unix.rb', line 28
def exist?
@exist ||= (
@backend.run_command("test -e #{@spath}")
.exit_status == 0
)
end
|
#file_version ⇒ Object
64
65
66
|
# File 'lib/train/extras/file_unix.rb', line 64
def file_version
nil
end
|
#link_path ⇒ Object
41
42
43
44
45
|
# File 'lib/train/extras/file_unix.rb', line 41
def link_path
return nil unless symlink?
@link_path ||=
@backend.run_command("readlink #{@spath}").stdout.chomp
end
|
#link_target ⇒ Object
35
36
37
38
39
|
# File 'lib/train/extras/file_unix.rb', line 35
def link_target
return @link_target if defined? @link_target
return @link_target = nil if link_path.nil?
@link_target = @backend.file(link_path)
end
|
#mounted ⇒ Object
47
48
49
50
|
# File 'lib/train/extras/file_unix.rb', line 47
def mounted
@mounted ||=
@backend.run_command("mount | grep -- ' on #{@spath}'")
end
|
#product_version ⇒ Object
60
61
62
|
# File 'lib/train/extras/file_unix.rb', line 60
def product_version
nil
end
|
#stat ⇒ Object
68
69
70
71
|
# File 'lib/train/extras/file_unix.rb', line 68
def stat
return @stat if defined?(@stat)
@stat = Train::Extras::Stat.stat(@spath, @backend)
end
|